Continue Statement
Continue statement is used in loops to skip the current iteration and move to next iteration. Think that you have a game and you don’t show the score of fourth stage to the player and add it at the end as a surprise.
You can implement this scenario as below using an array, a For loop and a continue statement.
$stages = array(50, 110, 130, 71, 203); $count = count($stages); for ($i=0; $i<$count; $i++) { if ($i == 3) { continue; } echo 'Stage '.($i+1).' Score: '.$stages[$i].'<br />'; }
After running, above code segment will print following lines in your web browser.
Stage 1 Score: 50
Stage 2 Score: 110
Stage 3 Score: 130
Stage 5 Score: 203
If you were inside a Nested For loop (say two levels) and once the condition becomes true, if you need to move to the next iteration of outer for loop then you can pass number of levels to skip as below.
continue(2);
In Switch Case control structure, in the place of break statement, continue statement can be used but it’s bit uncommon.