While loop is entry control loop.Disadvantage of “For” loop is we cannot use condition in the loop. In python , if we need a loop which works on condition then we go with while loop. Also if we need an infinite loop we can use while loop.
While Loop in Python
A while loop in Python is used to repeatedly execute a block of code as long as a specified condition is True. The loop continues executing as long as the condition remains True, and it terminates when the condition becomes False.
a=1
b=10
#loop with True condition
while(a<=b):
print(a,end=" ")
a+=1 #for incrementing a
print("\nValues at the point of terminating loop are : a={} and b={}".format(a,b))
Output:
1 2 3 4 5 6 7 8 9 10
Values at the point of terminating loop are : a=11 and b=10
Login/Signup to comment