Next / Previous / Contents / TCC Help System / NM Tech homepage

23.3. The continue statement: Jump to the next cycle of a for or while

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.

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