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





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")





Click to Enlarge


For loop




for  object_variable in collection:
            Statements to be executed.




name = "Karan"

for character in name:
    print (character)





Click to Enlarge



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

for name in classmates:
    print (name)





Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250