Python - Break Statement


A break in Python stops the Statement Loop on an expression.

Syntax for break statement

break


Example for break statement

In the example, if 'n' gets 4 then the iteration of for Loop stops.

 Break statement

Source Code:


nums = [1, 2, 3, 4, 5,6]
for n in nums:
    print (n)
    if (n == 5):
       break

Output:


1
2
3
4