Python break Keyword
Example
End the loop if i is larger than 3:
for i in range(9):
if i > 3:
break
print(i)
Try it Yourself »
Definition and Usage
The break
keyword is used to break out a
for
loop, or a while
loop.
More Examples
Example
Break out of a while loop:
i = 1
while i < 9:
print(i)
if i == 3:
break
i += 1
Try it Yourself »
Related Pages
Use the continue
keyword to end the current iteration in a loop, but continue with the next.
Read more about for loops in our Python For Loops Tutorial.
Read more about while loops in our Python While Loops Tutorial.