PHP continue is a keyword use within looping structures.
continue skip the current loop iteration and then begin the next iteration depending on condition.
continue also accepts numeric argument like continue 1, continue 2 etc.
The default value is 1, thus skipping to the end of the current loop.
From PHP 5.4.0, continue 0; is no longer valid.
In previous versions it was interpreted the same as continue 1.
Example
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php $i = 0; while ($i < 5) { $i++; if ($i == 3) continue; echo "$i"; } ?> |
Output:
1 |
1 2 4 5 |
Here it skip the value 3 due to continue.
PHP continue with arguments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php for ($i=0; $i<3; $i++) { echo "Start Of I loop<br>"; for ($j=0;;$j++) { if($j >= 2) { continue 2; } echo "$i $j <br>"; } echo " end"; } ?> |
Output:
1 2 3 4 5 6 7 8 9 |
Start Of first loop 0 0 0 1 Start Of first loop 1 0 1 1 Start Of first loop 2 0 2 1 |
Here when $j = 2, it skip ends execution of ‘if’ and inner ‘for’ loop.