Wiki
Version 2 (modified by todd.a, 13 years ago)

--

Continue Statement

The continue statement forces transfer of control to the controlling expression of the nearest (smallest) enclosing loop.

Any remaining statements in the current iteration are not executed. The next iteration of the loop is determined as follows:

  • In a while loop, the next iteration starts by reevaluating the controlling expression of the while statement.
  • In a for loop, continue causes the loop counter to increment or enumerator step to be executed
    then the loop termination cond-expr is reevaluated and, depending on the result, the loop either terminates or another iteration occurs.

Grammar

continue

Example

The following example shows how the continue statement can be used to bypass sections of code and begin the next iteration of a loop.

def main is shared
    i = 0
    post while i < 3    # do
        i += 1
        print 'before the continue'
        continue
        print 'after the continue, should never print'

     print 'after the do loop'

# Outputs:

before the continue
before the continue
before the continue
after the do loop