16. Breaking and Continuing Loops
Sometimes, you need to alter the standard flow of a loop based on a specific condition. PHP provides break and continue for this purpose.
The break Statement
break immediately terminates the execution of the current for, while, do-while, foreach, or switch structure.
Example: Stopping when a target is found.
php
"; } ?>The continue Statement
continue stops the current iteration of the loop and moves immediately to the next iteration (re-evaluating the condition).
Example: Skipping unwanted values.
php
"; } /* Output: Processing odd number: 1 Processing odd number: 3 ... */ ?>