break - To break out of a loop

A break statement terminates the nearest enclosing for or while loop.

Example of a break in a for loop:

Python
for x in range(10):
    if (x == 5):
        break
    print(x)

Output

0
1
2
3
4

Example of a break in a while loop:

Python
x = 0
while x < 10:
    if (x == 5):
        break
    print(x)
    x = x + 1

Output

0
1
2
3
4