Loops In Python
Python loop has a control flow statement to specify iteration. Which allows the code to be executed repeatedly. In simple terms, a loop is used to execute a statement multiple times.
A loop is a programming function in python that iterates a statement or condition based on specified limits.
The loop uses almost the same logic and syntax in all programming languages. Thus, a specific statement or group of instructions is executed continuously until a specific loop body or boundary condition is reached. The result of the first operation cycle of the entire loop body serves as the starting point for the next iteration.
Types of loop in python
- For Loop
- While Loop
- Do-While Loop
For Loop: For loops are used in the case where we need to execute some part of the code until the given condition is satisfied. The loop is also called a pre-tested loop. If the number of loops is known in advance, it is better to use for loops.
While Loop: While the loop is to be used in a scenario where we do not know the number of iterations beforehand. The block of statements is executed in a loop until the condition specified in the loop is satisfied. It is also called a pre-tested loop.
Do-While Loop: Do-While loop keep executing until the given condition is satisfied. It is also called a post-tested loop. It is used when it is necessary to execute a loop at least once (mostly menu-driven programs).
Loops In Python
Reviewed by Sk Jha
on
October 30, 2019
Rating:
No comments: