Loops in python

Share:


Loops:                                                                     

There  is 2 types of loops 
1- For Loop
2- While loop

For Loop 😉:

loop is used for executing a block of statements repeatedly until a particular condition is satisfied.

For example:

when you are displaying number from 1 to 100 you may want set the value of a variable to 1 and display it 100 times, increasing its value by 1 on each loop iteration.

While loop😊:

The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true. We generally use this loop when we don't know the number of times to iterate beforehand.

Different Between For Loop and While loop

For Loop

While Loop

The for statement iterates through a collection or iterable object or generator function.

The while statement simply loops until a condition is False.

If the condition is not put up in 'for' loop, then loop iterates infinite times. 

If the condition is not put up in 'whileloop, it provides compilation error.

 for loop is depend on range

 'while' loop is depends on condition True or false.