For any queries you can reach us at infovistarindia@gmail.com / WhatsApp us: +919158876092

Python Control Loops

Control Loops

  1. While Loop

    While Loop It is used to execute a block of a statement till a given condition is true. And when the condition becomes false, the control will exit from the loop. Every time at the beginning of the loop it checks the condition. For Loop It is used to iterate over items of any sequence, such as a list or a string. Nested For Loop For loop within for loop is what we mean by nested for loops.

    x=1  
    while x<=4 :  
          print(x)  
          x = x+1 

    In the above code, we are printing all the values from 1 to 4.

  2. For Loop

    It is used to iterate over items of any sequence, such as a list or a string.

    for i in range (3,5):  
          print(i) 

    In the above code, we are printing numbers from 3 to 5.

  3. Nested For Loop

    For loop within for loop is what we mean by nested for loops.

    for i in range (1,3):  
        for j in range(1,11):  
              k=i*j  
              print(k, end = ' ')  
        print() 

    In the above code, we are running our loop firstly from 1 to 3 and then for each iteration running for another 10 times.