gawk: Continue Statement

1 
1 7.4.7 The 'continue' Statement
1 ------------------------------
1 
1 Similar to 'break', the 'continue' statement is used only inside 'for',
1 'while', and 'do' loops.  It skips over the rest of the loop body,
1 causing the next cycle around the loop to begin immediately.  Contrast
1 this with 'break', which jumps out of the loop altogether.
1 
1    The 'continue' statement in a 'for' loop directs 'awk' to skip the
1 rest of the body of the loop and resume execution with the
1 increment-expression of the 'for' statement.  The following program
1 illustrates this fact:
1 
1      BEGIN {
1           for (x = 0; x <= 20; x++) {
1               if (x == 5)
1                   continue
1               printf "%d ", x
1           }
1           print ""
1      }
1 
1 This program prints all the numbers from 0 to 20--except for 5, for
1 which the 'printf' is skipped.  Because the increment 'x++' is not
1 skipped, 'x' does not remain stuck at 5.  Contrast the 'for' loop from
1 the previous example with the following 'while' loop:
1 
1      BEGIN {
1           x = 0
1           while (x <= 20) {
1               if (x == 5)
1                   continue
1               printf "%d ", x
1               x++
1           }
1           print ""
1      }
1 
1 This program loops forever once 'x' reaches 5, because the increment
1 ('x++') is never reached.
1 
1    The 'continue' statement has no special meaning with respect to the
1 'switch' statement, nor does it have any meaning when used outside the
1 body of a loop.  Historical versions of 'awk' treated a 'continue'
1 statement outside a loop the same way they treated a 'break' statement
11 outside a loop: as if it were a 'next' statement (⇒Next
 Statement).  (d.c.)  Recent versions of BWK 'awk' no longer work this
1 way, nor does 'gawk'.
1