Login
Your Email
Pasword
Home
Write
Trending
History
Liked
Dashboard

How many loops Python have?What are those loops?

Do you know how many loops Python support?

Do you have similar website/ Product?
Show in this page just for only $2 (for a month)
Create an Ad
0/60
0/180
Python  language has only two loops:
1.for loop 
2.while loop
For loop
 Syntax of For loop:
for i in iterating_object:
# show some output
All the statements inside "for"  and "while" loop should be indented to the same number of spaces. Otherwise it will throw the SyntaxError .
E.g:
my_result= [1,2,3,4]
 for i in my_result:
 print(i)
 range(a,b) Function
This range(a, b) functions returns sequence of integers from a , a + 1 , a+ 2 ?. , b - 2 , b - 1 . 
for i in range(5, 20):
 print(i)

While loop
While loop keeps executing statements inside it until condition becomes false. 
After each iteration condition is checked and if its True then once again statements inside the while loop will be executed.
Syntax of While loop is :
while condition:
 # body 
E.g:
cal = 0
 while cal < 10:
 print(count)
 cal += 1
In above example it will print until cal is less than 10.
CONTINUE READING
Loops
Python
Python Language
Ayesha
Tech writer at newsandstory