Python Break, Continue and Pass Statements
Python has provided with different loop control statements to control the flow of the loop.
Contents
What are Loop Control statements in Python?
Python provides three loop control statements:
- break
- continue
- pass
What is break loop control statement in Python?
The break statement is used to exit out of the loop. It stops the flow of execution of the current loop and passes to the next statements after the loop.
Syntax of break statement:-
break
Flowchart of break statement:-
Example of break statement:-
for i in range(0, 5): if i > 2: break print(i) print("Body after loop")
The output of break statement:-
1
2
Body after loop
What is continue loop control statement in Python?
The continue statement is used to continue with the existing loop body and pass the control to the beginning of the body without executing the next statement in loop.
The syntax of continue statement:-
continue
Flowchart of continue statement:-
Example of continue statement:-
for i in range(0, 5): if i == 2: continue print(i) print("Body after loop")
The output of continue statement:-
1
3
4
Body after loop
What is pass loop control statement in Python?
The pass statement is used to execute nothing in Python. It is a null statement in Python. It is used as a placeholder. It can be used when we have a loop or function or class that have not yet been implemented. Let’s use the following examples to have an idea of pass statement.
for i in range(0, 5): pass def sum(a, b): pass class Vehicle: pass