Hello dear readers! Welcome back to another edition of our tutorial on Python. In this tutorial guide, we are going to be discussing about the Loop control statements in Python.
Normally, statements are executed sequentially: The first statement in a function is executed first and then followed by the second, and so on. There may be a situation when you need to execute a block of code several number of times.
Python provides different control structures that allows for more complicated execution paths.
A loop control statement lets you to execute a statement or group of statements multiple times.
Normally, statements are executed sequentially: The first statement in a function is executed first and then followed by the second, and so on. There may be a situation when you need to execute a block of code several number of times.
Python provides different control structures that allows for more complicated execution paths.
A loop control statement lets you to execute a statement or group of statements multiple times.
Flow Chart
The following diagram illustrates the flow chart of the loop control statement in Python -
RECOMMENDED: Python Nested If Statements
Python provides its users with the following types of loops to handle various looping requirements -
Sr.No. | Loop Type & Description |
---|---|
1 | while loop
Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.
|
2 | for loop
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
|
3 | nested loops
You can use one or more loop inside any another while, for or do..while loop.
|
RECOMMENDED POST: Python if Statement Tutorial with examples
Loop Control Statements
Loop control statements in Python changes execution from its normal sequence. When execution leaves a scope, all the automatic objects that where created in that scope gets destroyed.
Below are the control statements supported by Python -
Below are the control statements supported by Python -
Sr.No. | Control Statement & Description |
---|---|
1 | break statement
Terminates the loop statement and transfers execution to the statement immediately following the loop.
|
2 | continue statement
Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
|
3 | pass statement
The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute.
|
RECOMMENDED POST: Python Operators
Alright guys! This is where we are rounding up for this tutorial. In our next tutorial, we will be discussing about the Python While Loops.
Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.