← Back to Blog

break — the emergency exit

The problem...

Your loop is running. It finds what it was looking for. But it keeps going anyway — checking every item that's left, doing work that doesn't need to be done.

There's no reason to continue. But the loop doesn't know that.

The idea!

break stops the loop immediately. The moment it executes — the loop is done. No more iterations. No more checks. Out.

The syntax

for item in sequence:
    if condition:
        break    # stop the loop immediately

Your first break

word = "RedHorn"

for letter in word:
    if letter == "H":
        print("Found H — stopping.")
        break
    print(letter)
# R
# e
# d
# Found H — stopping.

The loop hits "H" — prints the message — breaks. "o", "r", "n" are never touched.

continue vs break

word = "Bull"

# continue — skips one iteration, loop keeps going
for letter in word:
    if letter == "u":
        continue
    print(letter)
# B / l / l

# break — stops the loop entirely
for letter in word:
    if letter == "u":
        break
    print(letter)
# B

continue is polite — it skips and moves on. break is final — it stops everything.

A real example

word = input("Enter a word: ")
found = False

for letter in word:
    if letter.lower() in "aeiou":
        print(f"First vowel found: {letter}")
        found = True
        break

if not found:
    print("No vowels found.")

The loop searches for the first vowel. The moment it finds one — it stops. No need to check the rest.

Heads up!

  • break stops the entire loop — not just the current iteration
  • Everything after break in the loop is never reached
  • break always works with a condition — alone it would stop on the first iteration
  • continue skips one iteration — break ends the loop

The mindset shift

Stop thinking: "The loop has to finish."

Start thinking: "The loop stops when the job is done."

What you should understand now

  • break stops the loop immediately — no more iterations
  • Use it when you've found what you need and there's no reason to continue
  • continue skips one — break stops all
  • Everything after break in the loop block is ignored
[ login to bookmark ] // copied! 21 views · 1 min
// resources
Code Example break_statement.py
← prev continue — the polite skip next → The end of the loop might not be the end
// 0 comments
// No comments yet. Be the first.
// leave a comment

// Your comment will appear after approval.