Skip to content

while loop

The while loop continues to execute as long as a specified condition is True.

while loop Syntax:

while expression:
# statement to be executed if the expression evaluates to true

Examples:

# Using a while loop to print numbers from 1 to 5
count = 1
while count <= 5:
print(count)
count += 1