Python break statement
Python break statement
The Python break statement breaks the minimum closed for or while loop in the C language.
The break statement is used to terminate a loop statement. That is, if the loop condition does not have the False condition or the sequence is not completely recursive, the execution of the loop statement is also stopped.
The break statement is used in the while and for loops.
If you use nested loops, the break statement stops executing the deepest loop and starts executing the next line of code.
Break statement syntax in Python:
Break
Flowchart:
Instance:
#! /Usr/bin/pythonfor letter in 'python': # First Example if letter = 'H': break print 'current Letter :', letter var = 10 # Second Examplewhile var> 0: print 'current variable value: ', var = var-1 if var = 5: breakprint "Good bye! "
Execution result of the above instance:
Current Letter: PCurrent Letter: yCurrent Letter: tCurrent variable value: 10 Current variable value: 9 Current variable value: 8 Current variable value: 7 Current variable value: 6 Good bye!