all Python 3Loopsconstruct
continue
control
Statement that skips the rest of the loop body and moves on to the next iteration.
Syntax
continue
Watch out in while loops: continue jumps straight back to the condition check, skipping everything below it — if you increment the counter after the continue, the loop hangs forever. In a for loop there's no such trap: the iterator advances to the next item on its own.
Examples
for i in range(10):
if i % 2 == 0:
continue
print(i, end=" ") # → 1 3 5 7 9
for x in [1, 0, 3, 0, 5]:
if x == 0:
continue # пропустить ноль — деления на 0 не будет
print(100 // x, end=" ") # → 100 33 20
for ch in "hello world":
if ch == " ":
continue
print(ch, end="") # → helloworld
total = 0
for n in range(1, 11):
if n % 3 == 0:
continue
total += n
print(total) # → 37 — сумма 1..10 без кратных 3
See also
Open in the full glossarydocs.python.orgReport an inaccuracy