Error: loop that never ends
A loop that never ends because nothing in the body changes the tested variable, or the condition can never reach its exit value.
Understanding Error: loop that never ends in IGCSE Computer Science Paper 2
What it does: Count ← Count + 1 changes the tested variable each time round, so Count <= 5 eventually becomes FALSE. Num is tested in the condition, so it must be updated in the body. Output after the loop does not change Num. Adding positive numbers makes Total bigger, so Total < 0 never becomes TRUE. The condition needs to be one that can be reached, such as Total > 100. Count goes up from 1, so Count >= 1 stays TRUE forever. In the other loop, Count will eventually pass 10 and the loop will stop. The exit condition is impossible to satisfy, so the REPEAT loop never stops however many values are entered.
Common mistakes: Count goes down, so it moves away from the exit value and Count <= 5 stays TRUE forever. The update must be Count ← Count + 1. Num only increases, so Num > 0 is always TRUE and the loop never stops. The test points the wrong way. It should be WHILE Num < 20 DO.
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 232–241) and word search (Modules 232–253).
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
infinite loopFill in the Blanks
Spot the Error
Student with a class code? Join your class →