Infinite loops and updating the loop variable
A loop runs forever if nothing in its body changes the variable its condition tests. Updating count each time lets the condition become false so the loop stops.
Understanding Infinite loops and updating the loop variable in ACARA Digital Technologies Years 7–8
What it does: lives-- lowers lives each time round, so lives > 0 eventually becomes false. n only gets bigger, so n > 0 is always true and the loop never ends. The loop needs n to move toward 0. Using n-- would make n > 0 become false eventually. count++ updates the variable the condition tests, so the loop reaches an end.
Common mistakes: i-- makes i smaller each time, so it never reaches 5 and the loop never stops. It should be i++ so i counts up to 5. count only goes up, so count >= 0 is always true and the condition can never become false. It should be count < 5.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 599–610) and word search (Modules 583–613).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
while (count < 5) { count++; }Fill in the Blanks
Spot the Error
Student with a class code? Join your class →