Q. Loops in python!

For Loops:-

For loop is a versatile tool in python it can be used print same or differrent statements multiple number of times, for loops mainly used for fixed number of iterations, The for-loop is always used in combination with an iterable object, like a list or a range. The Python for statement iterates over the members of a sequence in order, executing the block each time

for i in range(0,5):
    print('My name is khan')

Above code will show output of my name is khan 5 times going from (0 to 4)

for loop code

nested for Loops:-

Nested for loops is, Using two or more than two for loops, in which 1 for loop in side of another in a way so that iteration of second one depends on first one. nested for loops are used for pattern printing mainly.

for i in range(5):
    for j in range(2):
        print('My name is khan')

Above code will show output of my name is khan 10 times going from (0 to 9). total number of iteration will be 10 as (5*2=10). and the complexity increses to O(n^2).

nested for output

While Loops:-

A while in python is used iterate a block of code until expresion holds is True. A while can also be used when we dont know fixed number of iterations unlike for loop.

n = 0
while(n<5):
     n=n+1
     print("charan")

If you know the answer tell us in the comments

There is No Do while loop in python