As we know, Loop are the statements which allows us to continuously repeat an instruction until the satisfaction of the condition.
Now, In this article we will learn about the python loop control statements and types of python loop control statements with examples.
Python Loop Control Statement
In python, to change the flow of normal execution and we can use these statements when we want to skip any iteration or to stop the sequence of execution. Simply we can say that python loop control statements are used by the programmers when they want to exit an entire iteration or want to skip some part when it meets the required condition. With loop control statements, we can alter the normal flow of sequence based on some specified conditions.
Types of Python Loop Control Statements
In python, there are three types of loop control statements which are explained as follows;
Python Break Statement
When the programmers want to terminate or stop the entire execution, then the break statement is used. Break statement is useful when we want to bring the control out of the loop and transfer the execution to the next immediate statement following that particular loop.
Python Break statement Example;
for i in range(10):if i > 5:
break
print(i)
Output
01
2
3
4
5
Python Continue Statement
Continue statement is used by the programmers when they want to end the present iteration or repetition after the meeting the required condition and to start the next iteration of the next loop straight away. Simply we can say that continue statement allows us to skip the current iteration based on the specific condition.
Python Continue statement Example;
for i in range(10):if i == 5:
continue
print(i)
Output
01
2
3
4
6
7
8
9
Python Pass Statement
Programmers use the pass statement when they don't want to perform anything after the requirement of the given condition. In simple words we can say that pass statement is a no statement which is generally used to show the unimplemented loop body.
Python Pass statement Example;
x = 1y = 2
if y > x:
pass
Conclusion
Above we have learnt about the python loop control statements and types of python loop control statements with examples. In python, to change the flow of normal execution and we can use these statements when we want to skip any iteration or to stop the sequence of execution. There are three types of loop control statements i.e., break, control and pass statement.