While loop in Python
While: it is a control statement all the statements will execute repetitively until the condition become false.
Syntax:
While condition:
Statements;
else Statement with Loops
If the else statement is used with a while loop, the else statement is executed when the condition becomes false.
Print the numbers from 1 to 50
a=1
while a<=50:
print(a)
a=a+1
print("end of loop")
note: print end of loop will run after loop terminates because it is from beginning of the line. If it is in the same statements line it will be a part of aloop.
Using else in while loop
a=1
while a<=50:
print(a)
a=a+1
else:
print("end of loop")
For
More Explanation
&
Online Classes
More Explanation
&
Online Classes
Contact Us:
+919885348743
+919885348743