Python Loops

Loop or Iterative statements are decision control statements that are used to repeat the execution of a list of statements. In Python, there are two types of loops are supported.

  • while loop
  • for loop
  • 1. while loop : while loop provides a mechanism to repeat one or more statements while a particular condition is TRUE. In While loop, the condition is tested before any of the statements in the statements block is executed, if the condition is TRUE then the statements will be executed otherwise if the condition is FALSE, the control will jump to another statement. It has the following syntax :

    statement x
    while(test condition):
    statement y

    2. for loop : for loop provides a mechanism to repeat a task until a particular condition is TRUE.
    for loop is also known as definite loop because this loop will repeat many times. range() function used in for loop to iterate over a sequence of numbers. It has the following syntax :
    for variable in range(initial range value, terminate range value)
    for variable in range(beg, end, step)
    Exmaple :
    for i in range(1,10)

    Recommended Posts:

        1. Python Features
        2. Python Applications
        3. Python Keywords
        4. Python installation
        5. Python variables and identifiers
        6. Python Data Types
        7. Python Operators
        8. Type Conversion in Python
        9. Python Program to Find Area Of Circle
        10. Python Conditional Statements : if-else, elif, nested if statements
        11. Python Loops
        12. Python Program to Check Armstrong Number
        13. Python Program to Print Pascal Triangle
        14. Python Program to Find the Square Root