Break ends the execution of the current for, foreach, while, do-while or switch structure. The break can accept an optional numeric parameter to determine the number of loops to jump out.
Break
(PHP 4, PHP 5)
Break ends the execution of the current for, foreach, while, do-while or switch structure.
The break can accept an optional numeric parameter to determine the number of loops to jump out.
\ N ";}/* use the optional parameter */$ I = 0; while (++ $ I) {switch ($ I) {case 5: echo" At 5
\ N "; break 1;/* only exits switch. */case 10: echo" At 10; quitting
\ N "; break 2;/* exit switch and while loop */default: break;}?>
Continue
(PHP 4, PHP 5)
Continue is used in the loop structure to skip the remaining code in this loop and start to execute the next loop when the condition value is true.
Note: In PHP, the switch statement is considered to be a loop structure that can use continue.
Continue accepts an optional numeric parameter to decide to skip multiple cycles to the end of the loop. The default value is 1, that is, jump to the end of the current loop.
\n"; while (1) { echo "Middle
\n"; while (1) { echo "Inner
\n"; continue 3; } echo "This never gets output.
\n"; } echo "Neither does this.
\n"; }?>
Omitting the semicolon after the continue will lead to confusion. The following example shows that you should not do this.
The expected result is:
0134
The actual output is:
2
Because the entire continue print "$ I \ n"; is evaluated as a single expression, therefore, the print function is called only when $ I = 2 is true (the print value is passed to continue as an optional numeric parameter ).