In while loop, the condition is evaluated first and if the condition is true then the statements inside while loop execute. When condition returns false, the control comes out of the loop.

Syntax


while expression:
 statements

Flow Diagram:




Eg:

a=0
while a<10:
 print(a, "is less than 10")
 a=a+1
else:
 print(a, "is not less than 10")

OUTPUT:

0 is less than 10
1 is less than 10
2 is less than 10
3 is less than 10
4 is less than 10
5 is less than 10
6 is less than 10
7 is less than 10
8 is less than 10
9 is less than 10
10 is not less than 10



Post a Comment

Previous Post Next Post