Loop in Python

  • Loop is a command which means repeat again an again using logics.
  • In python loops are two types:
    • while loop
    • for loop

    While loop in python

    • It is an entry-controlled looping statement.
    • It is used to repeat a block of statements until the condition becomes True.

    Syntax:

    while (condition):
     statement
     increments/decrements

    Example of while loop

    For loop in python

    • For is one type of python keyword.
    • A for loop is used for iterating the statements.
    • For loop is used in a list, a tuple, a set, a string, and a dictionary.
    Example

    Use of for loop

    y=[1,2,3,4,5,6,7] #This is a list
    for x in y:
     print(x)
    Output
    1
    2
    3
    4
    5
    6
    7
    English Hindi