continue skips the rest of the current iteration and jumps straight to the next one. Where break stops the loop, continue just abandons this item and carries on — perfect for filtering out cases you don't want to process.
Skipping items
for n in range(1, 8):if n % 2 == 0:continue # skip even numbers — go to the next nprint(n) # 1 3 5 7
The guard-clause pattern
continue keeps loops flat and readable by handling the "skip" cases up front, so the main logic isn't buried in deep indentation:
for row in rows:if not row.strip():continue # skip blank linesif row.startswith("#"):continue # skip commentsprocess(row) # the real work, un-indented
Key takeaways
- 01continue skips the rest of the current iteration and moves to the next.
- 02Use it to filter out cases you do not want to process.
- 03The loop keeps running — unlike break, which exits it.
- 04Guard clauses with continue keep the main loop body flat and readable.
