Skip to content
BENIBIX Learn

Break Statement

Development🧩 Programming ConceptsControl Flow

Also known as break, continue, Break and Continue

A line that stops a loop at once. Its partner continue skips to the next pass.

Think of it like

Think of it like a search for lost keys. Once you find them, you stop looking in the other rooms.

Example

A search loops over 10,000 users looking for one email. It finds it at user 12 and breaks, so it never checks the other 9,988.

Why it matters

Stopping early can save a lot of time on long lists. It is also the clean way out of a loop meant to run forever.

Definition

A break statement ends a loop at once, even if items are left. The program carries on with the first line after the loop. Its partner, continue, skips only the rest of this pass and moves to the next one. Both usually sit inside an if. They save work when the answer is found early.

Example code

python
for n in [4, 9, 2, 7]:
    if n == 2:
        print("found 2")
        break
    print("checked", n)
It checks 4 and 9, finds 2, then stops. It never looks at 7.

Common mistake

Expecting break to leave every loop at once. In nested loops it only leaves the one it sits in.

Key takeaways

  1. 1
    Break ends it. The loop stops right there.
  2. 2
    Continue skips one. Only the current pass is cut short.
  3. 3
    Inner loop only. It leaves the closest loop, not all of them.

Learn it properly