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.