Recommended Free Tools
Use break to leave the nearest loop; use continue to skip the rest of the current iteration and move to the next one. Both work in for and while loops. A loop’s optional else clause runs when the loop finishes without a break.
What each statement does
| Statement | Effect | Execution resumes |
|---|---|---|
break |
Ends the nearest enclosing for or while loop. |
At the first statement after that loop. |
continue |
Skips the rest of the current iteration. | At the next item in a for loop, or the next condition check in a while loop. |
For example, in a for loop, break stops processing further items, while continue skips just the current item and keeps the loop going. A for loop iterates over items from an iterable; a while loop runs as long as its condition remains true. See the Python tutorial on control flow.
As an Amazon Associate I earn from qualifying purchases.
When to use break
Use break when the loop’s task is complete and there is no reason to check more items or repeat again. In this example, the loop stops as soon as the condition is met:
for item in items:
if should_stop(item):
break
process(item)
The call to process(item) is not reached for the item that triggers break. Execution continues after the loop instead.
#1 Best Overall
When to use continue
Use continue when the current item should be ignored but later items still need processing:
for item in items:
if should_skip(item):
continue
process(item)
For an item that meets should_skip, the rest of the loop body is skipped. The next iteration begins; process(item) runs for items that are not skipped.
Rank #2
How they behave in nested loops
Both statements affect only the nearest enclosing loop. If an inner loop executes break, that inner loop ends and the outer loop continues. An inner-loop continue advances the inner loop; it does not skip the outer loop’s current iteration.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Python does not provide a label on break or continue for selecting an outer loop. They must be syntactically inside a for or while loop; putting one inside a function or class definition nested in the loop does not make it control the outer loop. The language reference for compound statements describes these rules.
How loop else works with break
A loop’s else clause runs if the loop completes without executing break. It belongs to the loop itself, not to an if inside the loop body. This is useful for searches: break when a match is found, and put the no-match action in the loop’s else.
for candidate in candidates:
if matches(candidate):
print("found", candidate)
break
else:
print("no match")
For a for loop, the else runs when the iterable is exhausted without a break. For a while loop, it runs when the condition becomes false without a break. If break exits the loop, the else suite is skipped. A return or a raised exception also prevents the loop’s else from running. The official tutorial’s control-flow examples include this search pattern.
What happens with finally
If control reaches a try statement’s finally clause while leaving a loop with break, or moving to the next iteration with continue, Python runs the finally clause first. The language reference for simple statements covers these control-flow rules.
Quick Recap
Best Value
Choose by the outcome you need
- Choose
breakwhen the whole loop should stop, such as when a search finds its target. - Choose
continuewhen only the current iteration should be skipped and the loop should carry on. - Use a loop
elsefor an action that should happen only if the loop ends withoutbreak.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




