Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

What is Looping in python?

Looping in python

Condition for Looping in python

  • Description: Looping in Python refers to the process of executing a block of code repeatedly based on a condition.Python has two loops 'for' and 'while'
Step-by-Step Process
  • for loop: The for loop iterates over each item in a sequence until all items have been processed.
  • while loop: The while loop repeatedly executes a block of code as long as a given condition remains true.
Sample Code
  • #for loop:
    fruits = ["apple", "banana", "cherry"]
    print("Output of for loop:")
    for i in fruits:
    print(i)
    print()
    #While loop:
    count = 0
    print("Output of while loop:")
    while count < 7:
    print("Count is:", count)
    count += 1
Screenshots
  • Looping in python