After reading this Python break statement topic, you will know its flowchart, theory, and examples, and you will understand how to use break statement with the loop.
Python while loop executes statements as long as expression evaluates true condition and when the expression evaluates false condition, the while loop gets terminate.
Python provides the break statements to give programmers more flexibility while designing the control logic of loops.
break statement
The break statement immediately terminates the loops (like while and for).
break statement Syntax:
The syntax of break statement is given below,
break
break statement flowchart:
The flow chart of break statement is given below,
Example
Program (1): To demonstrate the use of a break statement.
i=1 while i<=20: print("How are you") if i==5: #break the loop, for i=5 reach break i+=1
Output (1)
How are you How are you How are you How are you How are you