PHP continue Loop
Loops are a fundamental aspect of programming. They allow programmers to create code that repeats for some given number of repetitions, or iterations. The number of iterations can be explicit (6 iterations, for example), or continue until some condition is met ('until Hell freezes over'). This topic covers the different types of loops, their associated control statements, and their potential applications in
The continue keyword halts the current iteration of a loop but does not terminate the loop.
Just like the break statement the continue statement is situated inside the loop body. When executed, the continue statement causes execution to immediately jump to the loop conditional.
In the following example loop prints out a message based on the values in an array, but skips a specified value.
The expected output is:
I love to eat apple pie.
I love to eat cherry pie.
The continue statement may also be used to immediately continue execution to an outer level of a loop by specifying the number of loop levels to jump. For example, consider data such as Fruit Color Cost
Apple Red 1
Banana Yellow 7
Cherry Red 2
Grape Green 4
In order to only make pies from fruit which cost less than 5
When the continue 2 statement is executed, execution immediately jumps back to $data as $fruit continuing the outer loop and skipping all other code (including the conditional in the inner loop