Spot the Infinite Loop
Find the Mistake Medium
Question
This loop runs forever. What is wrong?
Code
let i = 0;
while (i < 10) {
console.log(i);
i - 1;
}
Hint
The loop variable needs to actually change.
Explanation
The line i - 1 calculates i minus 1 but does not assign the result back to i. So i stays 0 forever, and i < 10 is always true. The fix is i = i - 1 or i++ (if the intent was to increment toward 10). Without reassignment, the loop variable never changes.
Related Resources
Related Lessons
- Loops (for & while)
Learn how for and while loops work.
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.