Computer Science
Infinite Loop from a Missing Update
Students write a loop whose condition can stay true forever because the loop variable never changes.
Quick check
Why students make it
They focus on the condition and the work inside the loop, then assume the loop will eventually move forward on its own. In most loops, the program only makes progress if the code explicitly updates the state that controls the condition.
The rule done right
Every loop must change something that can make its condition become false. For a counter loop, update the counter on every path through the loop, such as increasing until .
Related resources
- Programming Fundamentals Cheat Sheet
- Algorithms & Big-O Notation Cheat Sheet
- AP Computer Science A Java Reference Cheat Sheet
- CS, Loops and Control Flow Worksheet
- CS, Functions and Parameters Worksheet
- CS, Python, Conditionals (if/elif/else) Worksheet
- CS, Recursion and Base Cases Worksheet
- Debugging & Unit Testing Explorer Tool
- CPU Instruction Cycle Simulator Tool
- Loops & Pattern Coder Tool
- Selection & Iteration Code Tracing Lab Lab
- Selection & Iteration Lab Lab
- Loops, Debugging & Animation Lab Lab
- Debugging & Unit Testing Lab Lab