Latest web development tutorials

Python break statement

Python break statement, like in C language, breaking the minimum closure for or while loop.

break statement to terminate the loop statement, loop condition that is not False condition or recursive sequence has not been fully completed, will stop the loop statement.

break statement is used in a while and for loops.

If you use nested loops, break statement to stop the execution of the innermost loop and start the next line of code.

Python language break statement syntax:


flow chart:



for letter in 'Python':     # First Example
   if letter == 'h':
   print 'Current Letter :', letter
var = 10                    # Second Example
while var > 0:              
   print 'Current variable value :', var
   var = var -1
   if var == 5:

print "Good bye!"

The results of the above examples:

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!