Home >>Python Keywords >Python break Keyword

Python break Keyword

Python break Keyword

Python break keyword is used to break out of a for loop or a while loop. Using this keyword, we get out of the loop as soon as the break condition satisfies without finishing the loop iteration.

Here is an example of Python break keyword:

for i in range(9):
if i > 5:
break
print(i)

Output:
0
1
2
3
4
5
Example 2:

i = 1
while i < 9:
print(i)
if i == 7:
break
i += 1

Output:
1
2
3
4
5
6
7