while <<expression>>:
statements
....
....
no_of_arrows = 10
while no_of_arrows > 0 :
no_of_arrows = no_of_arrows -1
print ("Number of arrows left in the container" + str(no_of_arrows))
print ("All arrows in the container is over and while loop completed")
>>>
============ RESTART: C:/Users/swadhin.ray/Desktop/While_loop.py ============
Number of arrows left in the container 9
Number of arrows left in the container 8
Number of arrows left in the container 7
Number of arrows left in the container 6
Number of arrows left in the container 5
Number of arrows left in the container 4
Number of arrows left in the container 3
Number of arrows left in the container 2
Number of arrows left in the container 1
Number of arrows left in the container 0
All arrows in the container is over and while loop completed
>>>
for x in 'apple':
print ('Lits of letters in apple :',x)
print ("Apple letter over!")
============= RESTART: C:/Users/swadhin.ray/Desktop/for_loop.py =============
Lits of letters in apple : a
Lits of letters in apple : p
Lits of letters in apple : p
Lits of letters in apple : l
Lits of letters in apple : e
Apple letter over!
>>>
names = ['Ray', 'Mike', 'David']
for j in names:
print ( j , ' is a name')
============= RESTART: C:/Users/swadhin.ray/Desktop/for_loop.py =============
Ray is a name
Mike is a name
David is a name
>>>
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)