PHPContinue Statement
The PHP Continue Statement
The PHPcontinue statement is used to skipthe current iteration of a loop, and continue with the next iteration.
Thecontinue statement is used in:
forloopswhileloopsdo...whileloopsforeachloops
PHP continue in For Loops
Thecontinue statement skips the current iteration in thefor loop and continue with the next.
Example
Skip, and move to next iteration if$x = 4:
for ($x = 0; $x < 10; $x++) { if ($x == 4) { continue; } echo "The number is: $x <br>";}Try it Yourself »PHP continue in While Loop
Thecontinue statement skips the current iteration in thewhile loop and continue with the next.
Example
Skip, and move to next iteration if$x = 4:
$x = 0;while($x < 10) { if ($x == 4) { continue; } echo "The number is: $x <br>"; $x++;}Try it Yourself »PHP continue in Do While Loop
Thecontinue statement skips the current iteration in thedo...while loop and continue with the next.
Example
Skip, and move to the next iteration if$i is 3:
$i = 0;do { $i++; if ($i == 3) continue; echo $i;} while ($i < 6);Try it Yourself »PHP continue in Foreach Loop
Thecontinue statement skips the current iteration in theforeach loop and continue with the next.
Example
Skip, and move to the next iteration if$value is "blue":
$colors = array("red", "green", "blue", "yellow");foreach ($colors as $value) { if ($value == "blue") continue; echo "$value<br>";}Try it Yourself »
