Question 1
0478 Paper 2 — style2 marksIdentify the error in the algorithm below and state the correction. [2 marks]
Count ← 0
REPEAT
INPUT Value
Count ← Count + 1
UNTIL Count > 5
OUTPUT Count
The algorithm is meant to read exactly 5 values, but it reads 6.
Model answer
Error: the loop condition UNTIL Count > 5 stops only once Count reaches 6, so the body runs one extra time (an off-by-one error).
Correction: change the condition to UNTIL Count >= 5 (equivalently UNTIL Count = 5).
Count ← 0
REPEAT
INPUT Value
Count ← Count + 1
UNTIL Count >= 5
OUTPUT Count
Why this scores
1 mark — identify the off-by-one / wrong condition. 1 mark — correct it (> 5 → >= 5 or = 5). AO3: testing the loop at its exit boundary reveals the extra iteration.