Python break statement
The Python break statement, like in C, breaks the minimally enclosed for or while loop.
The break statement is used to terminate the loop statement. That is, if the loop condition does not have a False condition or the sequence has not been completely recursed, the execution of the loop statement will also be stopped.
The break statement is used in while and for loops.
If you use nested loops, the break statement will stop execution of the deepest loop and start execution of the next line of code.
Python language break statement syntax:
break
Flow chart:
Example:
!/usr/bin/python
for letter in 'Python': # First Example
if letter == 'h':
break
print 'Current Letter:', letter
var = 10 rent variable value :', var
var = var -1
if var == 5:
break
print "Good bye!"
The above example is executed Result: for letter in 'Python': # First Example
if letter == 'h':
break
print 'Current Letter:', letter
var = 10 rent variable value :', var
var = var -1
if var == 5:
break
print "Good bye!"
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!
Current variable value : 10
Current variable value : 9
Current variable value : 8
Current variable value : 7
Current variable value : 6
Good bye!