Find Mistake: Infinite While Loop
Find the Mistake Easy
Question
This code runs forever. What is wrong?
Code
i = 0
while i < 5:
print(i)
Hint
The loop variable never changes.
Explanation
The variable i is never incremented inside the loop, so the condition i < 5 is always true. The fix is to add i += 1 inside the loop body to ensure progress toward the termination condition.
Related Resources
Related Lessons
- Conditions and Loops
While loop pitfalls.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.