Articles → Python → Loops in python

Loops in python






What are loops?





Types of loops











While loop




While condition:
      Statements to be executed




x  = 0

while x < 10:
    print ("Value of x is ", x)
    x = x + 1




Picture showing the output of the while loop in python

Click to Enlarge



x  = 0

while x < 10:
    print ("Value of x is ", x)
    x = x + 1
else:
    print("Value of x is equal to 10")




Picture showing the output of the while loop in python

Click to Enlarge


For loop




for  object_variable in collection:
            Statements to be executed.




name = "Karan"

for character in name:
    print (character)




Picture showing the output of the for loop in python

Click to Enlarge



classmates = ["Karan","sumit","amit"]

for name in classmates:
    print (name)




Picture showing the output of the for loop through collection in python

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, February 18, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250