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 ii until i≥ni \ge n.