PythonBreak Statement
The Python break statement, like in the C language, breaks the minimum enclosing for or while loop.
The break statement terminates the Loop statement, that is, the loop condition does not have a false condition, or the sequence is not fully recursive, and the loop statement is stopped.
The break statement is used in the while and for loops.
If you use a nested loop, the break statement stops executing the deepest loop and starts executing the next line of code.
Python language break statement syntax:
Break
Flow chart:
Instance:
#!/usr/bin/python for Letterinch ' Python ': # First Example if Letter== ' h ': Break Print ' Current letter: ', Lettervar = Ten # Second Example while var > 0: Print ' current variable value: ', var var = var -1 if var == 5: BreakPrint "Good bye!"
The result of the above instance execution:
Current Letter :P Current Letter :y Current Letter :T CurrentVariable Value: Ten CurrentVariable Value: 9 CurrentVariable Value: 8 CurrentVariable Value: 7 CurrentVariable Value: 6GoodBye!
Python Break statement