The while loop is used to execute a piece of code as long as the test condition is true. While loop is preferred whenever the number of iterations is not known.
Syntax

Example
num=5
count=1
while count <= num:
print("The current number is:",count)
count+=1
Output
The current number is: 1
The current number is: 2
The current number is: 3
The current number is: 4
The current number is: 5
In the above example, while loop will check the condition continuously the value count and compare with num value as long as condition is true. In case of true all the statement inside the while loop will execute.
You must log in to post a comment.