gawk: Next Statement

1 
1 7.4.8 The 'next' Statement
1 --------------------------
1 
1 The 'next' statement forces 'awk' to immediately stop processing the
1 current record and go on to the next record.  This means that no further
1 rules are executed for the current record, and the rest of the current
1 rule's action isn't executed.
1 
11    Contrast this with the effect of the 'getline' function (⇒
 Getline).  That also causes 'awk' to read the next record immediately,
1 but it does not alter the flow of control in any way (i.e., the rest of
1 the current action executes with a new input record).
1 
1    At the highest level, 'awk' program execution is a loop that reads an
1 input record and then tests each rule's pattern against it.  If you
1 think of this loop as a 'for' statement whose body contains the rules,
1 then the 'next' statement is analogous to a 'continue' statement.  It
1 skips to the end of the body of this implicit loop and executes the
1 increment (which reads another record).
1 
1    For example, suppose an 'awk' program works only on records with four
1 fields, and it shouldn't fail when given bad input.  To avoid
1 complicating the rest of the program, write a "weed out" rule near the
1 beginning, in the following manner:
1 
1      NF != 4 {
1          printf("%s:%d: skipped: NF != 4\n", FILENAME, FNR) > "/dev/stderr"
1          next
1      }
1 
1 Because of the 'next' statement, the program's subsequent rules won't
1 see the bad record.  The error message is redirected to the standard
1 error output stream, as error messages should be.  For more detail, see
1 ⇒Special Files.
1 
1    If the 'next' statement causes the end of the input to be reached,
1 then the code in any 'END' rules is executed.  ⇒BEGIN/END.
1 
1    The 'next' statement is not allowed inside 'BEGINFILE' and 'ENDFILE'
1 rules.  ⇒BEGINFILE/ENDFILE.
1 
1    According to the POSIX standard, the behavior is undefined if the
1 'next' statement is used in a 'BEGIN' or 'END' rule.  'gawk' treats it
1 as a syntax error.  Although POSIX does not disallow it, most other
1 'awk' implementations don't allow the 'next' statement inside function
1 bodies (⇒User-defined).  Just as with any other 'next' statement,
1 a 'next' statement inside a function body reads the next record and
1 starts processing it with the first rule in the program.
1