← IGCSE Computer Science Paper 2

FOR loop with STEP (7c)

Sets how much the FOR loop variable changes each time round. STEP 2 counts in twos and STEP -1 counts down. The loop stops when the value goes past the end value.

Understanding FOR loop with STEP (7c) in IGCSE Computer Science Paper 2

What it does: STEP 2 adds 2 to Number after each pass of the loop, so OUTPUT shows 2, 4, 6, 8 and 10. Without STEP the loop counts up by 1, so starting at 10 it is already past 1 and never runs. STEP -1 makes it count down. X goes 1, 3, 5, 7, 9. The next value is 11, which is past 10, so the loop stops. STEP comes after the end value: FOR variable ← value1 TO value2 STEP amount.

Common mistakes: NEXT must name the same loop variable that the FOR line uses. The loop variable is Number, so the line should be NEXT Number. Counting down from 5 to 1 needs a negative step. STEP 1 counts up, so the value is already past the end value and the loop never runs. It should be STEP -1.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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 166–175) and word search (Modules 166–187).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which loop counts down from 10 to 1?
FOR Count ← 10 TO 1 STEP -1FOR Count ← 10 TO 1
Matches
FOR Count ← 10 TO 1 OUTPUT Count NEXT Count
↓
There is no STEP -1, so the loop counts up by 1 by default. Because 10 is already past 1, the loop body never runs. It should be FOR Count ← 10 TO 1 STEP -1.
Applying
Meanings
Term
STEP
Meaning
Sets how much the FOR loop variable changes each time round. STEP 2 counts in twos and STEP -1 counts down. The loop stops when the value goes past the end value.
Practice
FOR Count ← 5 TO 1 STEP -1
Testing
Gaps
FOR Num ← 2 TO 10 2
Check Answer
Spots
3 OUTPUT Number
4NEXT Count

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Squirrel' badge — Module Hoarder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which loop counts down from 10 to 1?
A. FOR Count ← 10 TO 1
B. FOR Count ← 10 TO 1 STEP -1 ✓
Without STEP the loop counts up by 1, so starting at 10 it is already past 1 and never runs. STEP -1 makes it count down.
2. Which loop outputs only the even numbers 2, 4, 6, 8, 10?
A. FOR Num ← 2 TO 10 STEP 2 ✓
B. FOR Num ← 2 TO 10 STEP 1
STEP 2 adds 2 each time round. STEP 1 would output every number from 2 to 10.
3. How many times does FOR N ← 1 TO 10 STEP 3 run?
A. 4 times (N is 1, 4, 7, 10) ✓
B. 3 times (N is 3, 6, 9)
The loop starts at the first value, 1, and adds 3 each time. It runs for 1, 4, 7 and 10, then 13 is past 10.
4. Which statement about STEP is correct?
A. STEP can be negative to count down ✓
B. STEP must always be a positive number
A negative STEP such as STEP -1 makes the loop variable go down each time round.
5. FOR X ← 1 TO 10 STEP 2: what is the last value of X used inside the loop?
A. 10
B. 9 ✓
X goes 1, 3, 5, 7, 9. The next value is 11, which is past 10, so the loop stops.

Match the Pairs

FOR Count ← 2 TO 10 STEP 2 → Counts in twos: Count takes the values 2, 4, 6, 8, 10, so the loop runs 5 times
FOR Count ← 5 TO 1 STEP -1 → Counts down: Count takes the values 5, 4, 3, 2, 1, so the loop runs 5 times
STEP sets how much the loop variable changes each time round, so STEP 2 gives the even numbers 2, 4, 6, 8, 10 → FOR Number ← 2 TO 10 STEP 2 OUTPUT Number NEXT Number
A negative STEP counts down, and the loop ends when the value goes past value2 (below 1 here) → FOR Number ← 3 TO 1 STEP -1 OUTPUT Number NEXT Number
FOR Count ← 10 TO 1 OUTPUT Count NEXT Count → There is no STEP -1, so the loop counts up by 1 by default. Because 10 is already past 1, the loop body never runs. It should be FOR Count ← 10 TO 1 STEP -1.
FOR Count ← 1 TO 10 STEP 2 OUTPUT Count NEXT Count → This outputs 1, 3, 5, 7, 9 (odd numbers) not the even numbers. To output even numbers it should start at 2: FOR Count ← 2 TO 10 STEP 2.

Key Term

STEP
Sets how much the FOR loop variable changes each time round. STEP 2 counts in twos and STEP -1 counts down. The loop stops when the value goes past the end value.

Fill in the Blanks

1. FOR Num ← 2 TO 10 STEP 2 OUTPUT Num NEXT Num
Hint: Type the keyword that sets how much the loop variable changes each time round.
2. FOR Count ← 10 TO 1 STEP -1 OUTPUT Count NEXT Count
Hint: Type the negative step value that makes the loop count down one at a time.
3. FOR Num ← 0 TO 10 STEP 2 OUTPUT Num NEXT Num
Hint: Type the step value that makes the loop go through only the even numbers.
4. FOR Num ← 10 TO 0 STEP -2 OUTPUT Num NEXT Num
Hint: Type the loop variable name that must follow NEXT to close the loop.
5. FOR Count ← 20 TO 0 STEP -5 OUTPUT Count NEXT Count
Hint: Type the keyword that comes before the end value in a FOR loop.

Spot the Error

Question 1
A OUTPUT "Even numbers"
B FOR Number ← 2 TO 10 STEP 2
C OUTPUT Number
D NEXT Count
Line D — NEXT must name the same loop variable that the FOR line uses. The loop variable is Number, so the line should be NEXT Number.
Question 2
A OUTPUT "Countdown"
B FOR Count ← 5 TO 1 STEP 1
C OUTPUT Count
D NEXT Count
Line B — Counting down from 5 to 1 needs a negative step. STEP 1 counts up, so the value is already past the end value and the loop never runs. It should be STEP -1.
Question 3
A DECLARE Num : INTEGER
B FOR Num ← 10 TO 0 STEP -2
C Num ← Num - 2
D NEXT Num
Line C — STEP -2 already lowers Num by 2 each time round, so the loop body must not change it by hand. The body should output the value with OUTPUT Num.
Question 4
A Total ← 0
B FOR Num ← 2 TO 10 STEP 2
C Total ← Num
D NEXT Num
E OUTPUT Total
Line C — This replaces Total with the current value each time round instead of adding to it. To total the even numbers it should be Total ← Total + Num.
Question 5
A DECLARE Odd : INTEGER
B FOR Odd ← 1 TO 9 BY 2
C OUTPUT Odd
D NEXT Odd
Line B — The keyword that sets the change in the loop variable is STEP, not BY. The line should be FOR Odd ← 1 TO 9 STEP 2.

Student with a class code? Join your class →