Home >Backend Development >PHP Tutorial >The difference between continue break exit return in php

The difference between continue break exit return in php

藏色散人
藏色散人forward
2019-11-07 13:49:493404browse

The loops in php include for foreach while do{} whlie.

1, continue

continue is used in the loop structure to control the program to give up the current loop continue; the statement after

, and transfer And enter the next cycle.

continue itself does not jump out of the loop structure but just gives up this loop.

Note: If continue is used in a non-loop structure (if switch), it will cause a program error.

2. break

The function of break is to jump out of the current syntax structure. The break statement can take a parameter n, indicating the number of layers to jump out of.

3. exit

exit ends program execution and can be used anywhere.

4. return

The return statement is used to end a piece of code and return a parameter.

If used in the main program, the main program will stop execution immediately.

For example:

<?php
for($i = 1000;$i >= 1 ; $i-- ){
if( sqrt($i) >= 30){
    echo $i."</br>";
}
else{
    return;
}
}
echo"本行将不会被输出";

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of The difference between continue break exit return in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete
Previous article:php install zip moduleNext article:php install zip module