while: warming up
The while loop is like a repeated if statement. The code is executed over and over again, as long as the condition is True
. Have another look at its recipe.
while condition :
expression
Can you tell how many printouts the following while
loop will do?
x = 1
while x < 4 :
print(x)
x = x + 1
This exercise is part of the course
Intermediate Python
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
