Lesson 7 of 55
PythonLoops – While
20 minutes
Course progress13%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 7 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
A while loop repeats a block of code as long as a condition remains true. It’s crucial to modify the loop variable inside the body; otherwise you’ll create an infinite loop.
counter = 0
while counter < 5:
print('Count:', counter)
counter += 1
When counter reaches 5, the condition becomes false and the loop exits.