Counting the passes of a FOR loop with STEP
Study this pseudocode.
FOR Count ← 10 TO 1 STEP -3
OUTPUT Count
NEXT Count
How many values are output?
A 3
B 4
C 9
D 10
[1]
- 1
List the values of Count. It starts at 10 and goes down by 3 each time while it is still 1 or more: 10, 7, 4, 1. The next value, −2, is past the end value, so the loop stops.
- 2
Four values are output. Answer B (1).
Answer
B (10, 7, 4, 1 are output)
Examiner tip
Examiner tip: with a negative STEP the loop counts down and runs while the counter is greater than or equal to the end value. Write the values out; do not try to work it out with a formula.
Common mistake: choosing A by forgetting that the end value 1 is reached exactly and is included.