100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Python

break, continue and pass in Python

Master Python's three loop control statements: break to exit early, continue to skip an iteration, and pass as a no-op placeholder.

Control FlowBeginner8 min readJul 7, 2026
Analogies

1. Introduction

Python provides three keywords to fine-tune the flow of loops and blocks: break immediately exits the nearest enclosing loop entirely; continue skips the rest of the current iteration and moves on to the next one; and pass does nothing at all — it's a placeholder used where Python syntactically requires a statement but you have no code to write yet.

🏏

Cricket analogy: An umpire calling 'over' ends the innings segment entirely like break, a no-ball simply voids that one delivery and moves to the next like continue, while a dead-ball signal that does nothing but mark time is like pass.

These three keywords are simple individually but are frequently combined with if conditions inside for and while loops to build precise control logic.

🏏

Cricket analogy: A captain combines 'if the batsman is dangerous, change bowler' logic across overs, mixing break, continue, and pass conditions the way a for loop over deliveries uses if statements to fine-tune field placement each ball.

2. Syntax

python
for item in iterable:
    if some_condition:
        break        # exit the loop immediately
    if other_condition:
        continue     # skip to the next iteration
    if not_ready:
        pass         # do nothing, placeholder
    process(item)

3. Explanation

break stops the loop entirely — control jumps to the first statement after the loop, and any loop else clause is skipped. continue jumps back to the top of the loop for the next iteration, re-checking the loop's condition (for while) or fetching the next element (for for), skipping any remaining code in the current pass. pass, by contrast, doesn't affect control flow at all; it's purely a syntactic filler for empty blocks, such as an unimplemented function body, an empty class, or an if branch you haven't written yet.

🏏

Cricket analogy: When a captain declares the innings early (break), the team skips straight to the next match, bypassing any 'if all overs bowled' bonus clause, while asking for a re-bowl of a no-ball (continue) just restarts that one delivery, and a pencil note 'field placement TBD' (pass) is pure filler.

In nested loops, break and continue only affect the innermost loop that directly contains them — they do not propagate to outer loops automatically.

🏏

Cricket analogy: A bowler ending his over early (break) only stops that over, not the whole innings — the outer 'match' loop of overs keeps going, just as break/continue in Python only affects the innermost enclosing loop.

A common use of pass is stubbing out code during development: 'def not_yet_implemented(): pass' lets the function exist and be callable (returning None) without raising a syntax error, so you can fill in the logic later.

break and continue only apply to the nearest enclosing loop. To break out of multiple nested loops, you typically need a flag variable, a custom exception, or restructuring into a function with an early return — Python has no labeled break like Java or C.

4. Example

python
numbers = [1, 2, 3, 4, 5, 6, 7, 8]

for n in numbers:
    if n == 6:
        break            # stop entirely once we hit 6
    if n % 2 != 0:
        continue          # skip odd numbers
    print(n)

for n in numbers:
    if n > 3:
        pass               # placeholder, does nothing special yet
    print(f"checked {n}")

5. Output

text
2
4
checked 1
checked 2
checked 3
checked 4
checked 5
checked 6
checked 7
checked 8

6. Key Takeaways

  • break exits the nearest enclosing loop immediately, skipping any loop else clause.
  • continue skips the remainder of the current iteration and moves to the next one.
  • pass is a true no-op used only to satisfy Python's syntax where a statement is required.
  • break and continue affect only the innermost loop they are written in.
  • Python has no labeled break/continue; use flags, exceptions, or functions for nested-loop exits.
  • pass is common in stub functions, empty classes, and placeholder if/except branches.

Practice what you learned

Was this page helpful?

Topics covered

#Python#PythonProgrammingStudyNotes#Programming#BreakContinueAndPassInPython#Break#Continue#Pass#Syntax#StudyNotes#SkillVeris