DEV Community

Sajin Joe J
Sajin Joe J

Posted on

Python : While Loop

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
Enter fullscreen mode Exit fullscreen mode

Output :

1
2
3
4
5
Enter fullscreen mode Exit fullscreen mode

Top comments (0)