Skip to main content

Python Loop Control Statements

Satellite · Control Flow

Loop Control Statements

Fine-tune loop behavior with `break`, `continue`, `pass`, and `else` blocks.

Examples

for task in tasks:
if task.error:
break # stop processing
if task.done:
continue # skip
process(task)
else:
print("No errors encountered")
  • break exits the loop immediately.
  • continue skips to the next iteration.
  • pass is a no-op placeholder.

Use loop else blocks to detect when loops finish naturally (no break).

Next up in your learning path