continue

continue abandons the current pass through the loop body: for moves on to the next item, while goes back to re-test its condition. The loop itself keeps running.

Control flowPython 3 (all)Live demo
continue in for
for x in items:
    if skip(x):
        continue
    use(x)
continue in while
while i < n:
    i += 1  # update first!
    if skip(i):
        continue
    use(i)
Use for
skip blanks / invalid rows / items you do not care about
Result
a statement — jumps to the next iteration of the innermost loop
Pairs with
for, while, if, break
Watch out
in while, anything below continue is skipped — including your i += 1

Demo

Live evaluation
Odd numbers are skipped with continue, even ones are used. The log shows every iteration and what happened in it.
Try:
Inputs
numberslistcomma-separated
Code
log = []
for n in [1, 2, 3, 4, 5, 6]:
    if n % 2:
        log.append(f"skip {n}")
        continue
    log.append(f"use {n}")
log
Result
['skip 1', 'use 2', 'skip 3', 'use 4', 'skip 5', 'use 6']

In the for tab, every number appears exactly once — as "skip" or "use", never both, because continue jumps past the second append. Negative odd numbers are skipped too: -3 % 2 is 1 in Python, not -1. 2.5 % 2 is 0.5, which is truthy, so 2.5 counts as odd. In the while tab, blank entries vanish; the i += 1 sits above the continue, so every pass moves forward.

Syntax slots

NameTypeRequiredDescription
(none)statementnocontinue takes no operand and no label. It must be inside a for or while body (not in a nested def or class); it affects only the innermost loop.

Common patterns

Skip blanks and comments
Filter early with continue, keep the main work unindented.
def parse(lines):
    for line in lines:
        line = line.strip()
        if not line or line.startswith("#"):
            continue
        yield line.split("=", 1)
Guard clauses inside a loop
Several continue checks instead of one deeply nested if.
def active_emails(users):
    for user in users:
        if not user.active:
            continue
        if not user.email:
            continue
        yield user.email
Or just filter
When the loop only collects, a comprehension with if replaces continue.
def non_empty(items):
    return [x for x in items if x]

Examples

1. Skip one item
for n in range(5): if n == 2: continue print(n)
Returns
0 1 3 4
2. Skip blanks
for word in ['a', '', 'b']: if not word: continue print(word)
Returns
a b
3. continue does not stop the loop
count = 0 for n in range(10): count += 1 continue count
Returns
10
4. continue in while re-tests the condition
i = 0 while i < 5: i += 1 if i % 2: continue print(i)
Returns
2 4
5. Only the innermost loop
for i in range(2): for j in range(3): if j == 1: continue print(i, j)
Returns
0 0 0 2 1 0 1 2
6. continue does not skip else
for n in [1, 2]: continue else: print('else runs')
Returns
else runs
7. finally runs on continue
for i in range(2): try: continue finally: print('finally', i)
Returns
finally 0 finally 1
8. continue outside a loop
compile('continue', '<demo>', 'exec')
Returns
SyntaxError: 'continue' not properly in loop

Pitfalls

1. continue before the update in a while loop
continue skips everything below it — here the i += 1 — so i stays at 2 and the loop never finishes. (A safety cap is added so the snippet ends.)
increment at the bottom
i = 0
seen = []
passes = 0
while i < 4:
    passes += 1
    if passes > 10:  # safety cap
        break
    if i == 2:
        continue
    seen.append(i)
    i += 1
(seen, i)
([0, 1], 2)
or use for
seen = []
for i in range(4):
    if i == 2:
        continue
    seen.append(i)
seen
[0, 1, 3]
2. Using continue where you meant pass
pass does nothing and the code below still runs; continue skips it. They are not interchangeable placeholders.
continue as "do nothing"
out = []
for n in [1, -2, 3]:
    if n < 0:
        continue  # TODO handle negatives
    out.append(n)
out
[1, 3]
pass keeps the rest
out = []
for n in [1, -2, 3]:
    if n < 0:
        pass  # TODO handle negatives
    out.append(n)
out
[1, -2, 3]
3. Expecting continue to move the outer loop
continue restarts only the innermost loop. To skip to the next outer item, break out of the inner loop (and use for / else if needed).
continue in the inner loop
rows = [[1, -1, 2], [3, 4]]
totals = []
for row in rows:
    total = 0
    for x in row:
        if x < 0:
            continue  # meant: skip this row
        total += x
    totals.append(total)
totals
[3, 7]
break + for / else
rows = [[1, -1, 2], [3, 4]]
totals = []
for row in rows:
    total = 0
    for x in row:
        if x < 0:
            break
        total += x
    else:
        totals.append(total)
totals
[7]

When to use

Use it
  • Skipping items that fail a check while the loop does real work on the rest
  • Flattening nested ifs in a long loop body into guard clauses
Reach for something else
  • A loop that only filters and collects → a comprehension with if
  • Stopping the loop entirely → break
  • A placeholder that should do nothing → pass

Notes

CPython impl
In a for loop, continue jumps back to FOR_ITER (fetch the next item); in a while loop, back to the condition test
finally
continue inside try runs the finally block first; continue directly inside a finally clause is allowed since Python 3.8
else
continue never cancels a loop’s else — only break does

FAQ

break ends the whole loop; continue ends only the current iteration and the loop goes on with the next item (for) or the next condition check (while).