11.12 continue

continue [ <loopname> ]

The continue command terminates execution of the current iteration of for, foreach, do and while loops in an analogous manner to the continue statement in the C programming language. Execution resumes at the first statement of the next iteration of the loop, or at the first statement following the end of the loop in the case of the last iteration of the loop. For example, the following script will not print the numberĀ 2:

for i = 0 to 5
 {
  if (i==2)
   {
    continue
   }
  print i
 }

If several loops are nested, the continue statement only acts on the innermost loop. If the continue statement is encountered outside of any loop structure, an error results. Optionally, the for, foreach, do and while statements may be supplied with a name for the loop, prefixed by the word loopname, as in the examples:

for i=0 to 4 loopname iloop

foreach i in "*.dat" loopname DatafileLoop

When loops are given such names, the continue statement may be followed by the name of the loop whose iteration is to be broken, allowing it to act upon loops other than the innermost one.

See also the break command.