While loop in python
While loop executes a set of statements as long as a condition is true.
Syntax of while loop
while(condition):
#number of statements
Example of while loop to a series 1 to 5
i=1
while(i<6):
print(i,end=' ')
i=i+1
Output
1 2 3 4 5
Example of while loop to print a series 5 to 1
i=5
while(i>0):
print(i,end=' ')
i=i-1
Output
5 4 3 2 1