PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

break in Python

← All stacks

Theory

25/268

break in Python

break leaves the nearest loop immediately. No more rounds. Search: for n in nums: if n == target: print("found"); break. After you find it, don’t keep scanning. Nested loops: break only exits the inner one — the outer for still continues.

Trace: for i in range(1, 6): if i == 3: break; print(i) → 1 then 2. 3 is not printed. 4 and 5 never run. Say that output before you run.

break in Python — output — 1 then 2. When i is 3, break — 4 and 5 never print.

Exam tip

Trace break with a tiny for-loop.

Example

# break
for i in range(1, 6):
    if i == 3:
        break
    print(i)

break in Python — output: 1 then 2. When i is 3, break — 4 and 5 never print.

Short notes

  • DefExit nearest loop now.
  • RuleEarly stop when found.
  • TrapNested — only inner loop exits.

Questions

1

Explain break as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with break?

Previous← continue in PythonNextpass Statement in Python →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.