A while loop in Python is used to execute a block of code repeatedly as long as a condition is True.
while – Starts the loop.
condition – Checks whether the condition is True or False.
If True, the code executes.
If False, the loop stops.
i = 1
while i <= 5:
print(i)
i = i + 1
Output :
1
2
3
4
5
Top comments (0)