While Loop
A while loop in Python is a control flow statement that allows code to be executed repeatedly based on a given condition. The code block inside the while loop runs as long as the condition evaluates to True. Once the condition becomes False, the loop stops executing, and the program continues with the next statements after the loop.
Syntax: while loop
while condition:
# Code to execute while the condition is True
Python program that demonstrates the use of while loop
# Initialize the counter
counter = 1
# Start the while loop
while counter <= 5:
print(counter) # Print the current value of counter
counter += 1 # Increment the counter by 1
Outout
1
2
3
4
5