Continue

continue is actually a block that typically follows control statement like while or until. If there is a continue BLOCK attached to such a statment (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 in C.

In other words continue changes the designation of the next statement.  But redo statement skips continue block and starts the next iteration.

Thus typically is used to execute "finalizing statements in the bottom of theloop, for example 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 can apper within continue block and is executed as usual.  Same is true for redo. Next within coninue statent can produce infinite loops

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.

 
  1. while (EXPR) {
  2.    ### redo always comes here
  3.    do_something;
  4. } continue {
  5.    ### next always comes here
  6.    do_something_else;
  7.    # then back the top to re-check EXPR
  8. }
  9. ### last always comes here


Omitting 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.

When there is no BLOCK, continue is a function that falls through the current when or default block instead of iterating a dynamically enclosing foreach or exiting a lexically enclosing given. In Perl 5.14 and earlier, this form of continue was only available when the switch feature was enabled. See feature and Switch Statements in perlsyn for more information.