The continue Statement

The continue statement is similar to the break statement except that instead of stopping the loop entirely, only the current execution of the loop is stopped. Control is returned to the closing curly brace and the loop continues. Inside for loops, described below, increments will occur just as if control had reached the end of the loop otherwise.

As you might imagine, this function is used to skip parts of a loop when a condition is met. Listing 3.7 demonstrates this idea. Random numbers are generated inside a loop until ten numbers, each greater than the previous, are produced. Most of the time the body of the loop is skipped due to the if statement that triggers a continue statement.

Listing 3.7. The continue Statement ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.