break Exit loop
Last updated: 2026-09-22
break Exit loop
break terminates the nearest enclosing loop.
| Category | Keywords & Statements |
|---|---|
| Kind | Keyword / Statement |
| Python Version | all |
📝 Syntax
break
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
0 1 2 done
🏷️ Related Keywords / Statements
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat is the difference between `break` and `continue`?
A`break` immediately ends the whole loop and execution continues after the loop; `continue` only ends the current iteration and moves to the next one, skipping the remaining statements of this iteration.
QCan `break` jump out of the outermost of nested loops?
ANo. `break` only terminates the innermost loop it is in. To break out of multiple levels, use a flag variable combined with a condition, or extract the inner logic into a function and use `return`.
QAfter `break` exits a loop, will the `else` after the `for` run?
ANo. The `else` of `for`/`while` runs only when the loop finishes normally; when `break` interrupts it, `else` is skipped — this is exactly what distinguishes «found and exited» from «finished scanning, not found».