Break Statement of Python
The break statement can be used inside a for loop or while loop to come out of the loop. When 'break' is executed, the Python interpreter jumps out of the loop to process the next statement in the program.
Suppose, we want to display numbers from 10 to 1 in descending order using while loop. For this purpose, we can write a simple while loop as:
x = 10 while x>=1: print ('x=', x) x-=1 print("Out of loop")
If we want to break the loop execution on certain condition, then break statement will be useful.
Break Statement Example
while x>=1: print ('x=', x) x-=1 if x==5: break print("Out of loop")