[Solved] What are the different kinds of loops in python?
Explain
@natasha1305 there is a for loop along with its variants such as for loop with range, nested for loop and there is while loop.
In Python, there are three types of loops to handle the looping requirement: for loop, while loop, and nested loops.
for loop: A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). It executes a set of statements, once for each item in a list, tuple, set, etc
while loop: A while loop is used to execute a block of code repeatedly as long as the specified condition is true
Nested loops: A nested loop is a loop inside a loop. The “inner loop” will be executed one time for each iteration of the “outer loop”
There are Three types of loops in python
1. For loop:- It is used to iterate over data sequence like list,arrays,tuples etc.
2. While loop:-It continually executes the statements (code) as long as the given condition is TRUE.
3. Nested loop:-Nested loops mean using a loop inside another loop. We can use any type of loop inside any type of loop.
The three types of loops in Python programming are while loop, for loop, and nested loops.
Mainly there are three kinds of loops in python-
1.For Loop
2.While Loop
3.Nested Loop
- 14 Forums
- 1,836 Topics
- 5,052 Posts
- 0 Online
- 1,078 Members