Previous Next

Python while Loop

While loops in Python are applied to run a piece of code a number of times as long as a given condition holds true.

Example:

number = 1
while (number <= 5):
    print(number)
    number = number + 1

Output

1
2
3
4
5
Previous Next