Python break statement
It ends the current circle and continues execution at the following proclamation, much the same as the customary break articulation in C.
The most well-known use for break is the point at which some outer condition is set off requiring a hurried exit from a circle. The break statement can be utilized in both while and for loops.
In the event that you are utilizing settled circles, the break proclamation stops the execution of the deepest circle and begin executing the following line of code after the square.
The syntax for a break statement in Python is as follows −
#!/usr/bin/python for letter in 'Python': # First Example if letter == 'h': break print 'Current Letter :', letter var = 10 # Second Example while var > 0: print 'Current variable value :', var var = var -1 if var == 5: break print "Good bye!"
When the above code is executed, it produces the following result −
Current Letter : P Current Letter : y Current Letter : t Current variable value : 10 Current variable value : 9 Current variable value : 8 Current variable value : 7 Current variable value : 6 Good bye!