<script>ec(2);</script>
Sometimes you may want to let the unconditional loop begin and allow the statements within the brackets to decide when Exit the loop.
There are two special statements that can be used in loops: break and continue.
break statement terminates or For loop while continuing to execute the current code after the following loop (if any). Alternatively,
you can put a number after the discounted keyword to describe how to get rid of multiple levels of the loop structure. This way, deeply nested loops buried
in one statement can break the outermost loop.
<?php echo "<p><b>Example of using the Break statement:</b></p>"; for ($i=0; $i<=10; $i ) { if ($i==3){break;} echo "The number is ".$i; echo "<br />"; } echo "<p><b>One more example of using the Break statement:</b><p>"; $i = 0; $j = 0; while ($i < 10) { while ($j < 10) { if ($j == 5) {break 2;} // breaks out of two while loops教程 $j ; } $i ; } echo "The first number is ".$i."<br />"; echo "The second number is ".$j."<br />"; ?>
continueThe statement terminates the execution of a or For loop in the statement block and continues the execution of the next iteration loop
<?php echo "<p><b>Example of using the Continue statement:</b><p>"; for ($i=0; $i<=10; $i ) { if (i==3){continue;} echo "The number is ".$i; echo "<br />"; } ?> </td> </tr> </table>
The above is the detailed content of PHP: Example analysis of how Break and Continue break out of the loop. For more information, please follow other related articles on the PHP Chinese website!