Table of Contents
break statement in Python language
In this tutorial, you will learn how vto use the break statement and how to control flow of the loop in Python .
break can be used in both “while” and “for loop“. It controls the flow of the loops(for loop , while loop) and is used to terminate the control of loop.
Syntax
break;
flow diagram of break in python
How to work break in python for loop
How to work break in python while loop
for loop with break in Python
Program 1
When the above code is executed, The following output is displayed
1 2 3 4 End of the loop
At the above program, when val == 5, break statement is executed and the control of the loop exits from execution.
Program 2
When the above code is executed, The following output is displayed
While loop with break in Python
Program 1
When the above code is executed, The following output is displayed
1 2 3 4
At above program, when i== 5, break statement is executed and control of the loop exits from execution.
Program 2
When the above code is executed, The following output is displayed
Similar post
for loop with pass break continue statements
while loop with pass break continue statements