Use a continue statement inside a for or while loop when you want
to jump directly back to the top of the loop and go
around again.
If used inside a while loop, the
loop's condition expression is evaluated again.
If the condition is False, the loop is
terminated; if the condition is True,
the loop is executed again.
Inside a for loop, a continue statement goes back to the
top of the loop. If there are any values remaining
in the sequence of values that controls the loop, the
loop variable is set to the next value in sequence,
and the loop body is entered.
If the continue is executed during the
last pass through the loop, control goes to the
statement after the end of the loop.
Examples:
>>> i = 0 >>> while i < 10: ... print i, ... i += 1 ... if (i%3) != 0: ... continue ... print "num", ... 0 1 2 num 3 4 5 num 6 7 8 num 9 >>> for i in range(10): ... print i, ... if (i%4) != 0: ... continue ... print "whee", ... 0 whee 1 2 3 4 whee 5 6 7 8 whee 9