continue
This is usually a flow-control statement rather than a function.
If there is a continue attached to a
BLOCK (typically in a
while or foreach), it is always executed just before
the conditional is about to be evaluated again, just like the third part
of a for(;;) loop. Thus it can be
used to increment a loop variable, even when the loop has been continued
via the next statement (which is
similar to the C continue
statement).
last, next, or redo may appear within a continue block; last and redo behave as if they had been executed
within the main block. So will next,
but since it will execute a continue
block, it may be more entertaining.
while (EXPR) {
### redo always comes here
do_something;
} continue {
### next always comes here
do_something_else;
# then back the top to re–check EXPR
}
### last always comes hereOmitting the continue section
is equivalent to using an empty one, logically enough, so next goes directly back to check the condition
at the top of the loop. See the section Loop Control
in Chapter 4.
However, if the “switch” feature is enabled, continue is also an operator that exits the
current when or default block and, by default, falls through
to the next one. See the section The given Statement in Chapter 4.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access