Skip to content
UPEEC

break, continue and pass

break leaves a loop, continue skips to the next iteration, pass does nothing (a placeholder).

Beginner
Comments 0
for x in readings:
    if x < 0:
        continue      # skip bad values
    if x > 100:
        break         # stop the loop entirely
    total += x

def todo():
    pass              # body required but nothing to do yet

A loop's else block runs only when the loop wasn't stopped by break.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.