← IGCSE Computer Science Paper 2

FOR…TO…NEXT loop (7d)

Repeats the lines up to NEXT Count a fixed number of times. Count starts at 1, goes up automatically, and both the start and end values are included. STEP changes the jump.

Understanding FOR…TO…NEXT loop (7d) in IGCSE Computer Science Paper 2

What it does: STEP changes the size of the jump. Starting at 2 and adding 2 each time gives 2, 4, 6, 8, 10. The loop variable Count changes automatically, so OUTPUT Count shows 1, then 2, then 3, and NEXT Count ends the loop. Both the start value (1) and the end value (5) are included, so Count takes the values 1, 2, 3, 4, 5. Cambridge FOR loops use the ← assignment arrow and TO. They do not use DO (that belongs to WHILE) or = for assignment. With a negative STEP the loop counts down. It starts at 10 and goes 10, 9, 8 ... down to 1.

Common mistakes: The start value of a FOR loop is given with the assignment arrow, not an equals sign. It should be FOR Count ← 1 TO 5. NEXT must name the same loop variable that the FOR line uses. The loop variable is Count, so it should be NEXT Count.

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 265–274) and word search (Modules 254–274).

Take this worksheet further — free with Cloodit

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

Learning
Duo
How many times does this loop run? FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
5 times4 times
Matches
FOR Count ← 1 TO 5 OUTPUT Count NEXT
↓
NEXT does not name the loop variable. It should be NEXT Count.
Applying
Meanings
Term
FOR Count ← 1 TO 10
Meaning
Repeats the lines up to NEXT Count a fixed number of times. Count starts at 1, goes up automatically, and both the start and end values are included. STEP changes the jump.
Practice
FOR Count ← 1 TO 5
Testing
Gaps
FOR Count ← 1 5
Check Answer
Spots
1Total ← 0
2FOR Count = 1 TO 5

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

The 'Void Whale' badge — Definition Drifter, 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. How many times does this loop run? FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
A. 5 times ✓
B. 4 times
Both the start value (1) and the end value (5) are included, so Count takes the values 1, 2, 3, 4, 5.
2. Which line correctly ends a loop that begins FOR Index ← 1 TO 8?
A. NEXT Index ✓
B. ENDFOR Index
Cambridge pseudocode closes a FOR loop with NEXT followed by the loop variable. ENDFOR is not used.
3. Inside FOR Count ← 1 TO 10, what do you need to write to add 1 to Count each time round?
A. Count ← Count + 1 on the last line
B. Nothing, the loop does it automatically ✓
The FOR loop changes the loop variable by itself every time it reaches NEXT. Adding it yourself is a common mistake.
4. What is the first value of Count in FOR Count ← 3 TO 7?
A. 3 ✓
B. 4
The start value is included, so the loop begins with Count equal to 3.
5. What does STEP 2 do in FOR Count ← 1 TO 9 STEP 2?
A. The loop runs exactly 2 times
B. Count goes up by 2 each time: 1, 3, 5, 7, 9 ✓
STEP sets the size of the jump between values of Count. It does not set the number of repeats directly.

Match the Pairs

FOR Count ← 1 TO 5 → Starts a loop where Count is 1, 2, 3, 4, 5, so the lines inside repeat 5 times
NEXT Count → Marks the end of the FOR loop and names the loop variable that is increased by 1
A FOR loop with STEP 2 jumps by 2 each time, so Count takes the values 2, 4, 6, 8, 10 → FOR Count ← 2 TO 10 STEP 2
A complete FOR loop that outputs the numbers 1 to 3 using the loop variable → FOR Count ← 1 TO 3 OUTPUT Count NEXT Count
FOR Count ← 1 TO 5 OUTPUT Count NEXT → NEXT does not name the loop variable. It should be NEXT Count.
FOR Count ← 1 TO 5 OUTPUT Count Count ← Count + 1 NEXT Count → Count is increased inside the loop by hand. A FOR loop changes the loop variable automatically, so this line is wrong and should be removed.

Key Term

FOR Count ← 1 TO 10
Repeats the lines up to NEXT Count a fixed number of times. Count starts at 1, goes up automatically, and both the start and end values are included. STEP changes the jump.

Fill in the Blanks

1. FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
Hint: Type the keyword that separates the start value from the end value.
2. FOR Count ← 1 TO 10 OUTPUT Count * 2 NEXT Count
Hint: Type the keyword that begins a fixed-count loop.
3. FOR Total ← 1 TO 8 OUTPUT Total NEXT Total
Hint: Type the loop variable name that NEXT must match.
4. FOR Count ← 0 TO 10 STEP 2 OUTPUT Count NEXT Count
Hint: Type the keyword that changes how much the loop variable jumps each time.
5. FOR Count ← 10 TO 1 STEP -1 OUTPUT Count NEXT Count
Hint: Type the step value that makes the loop count downwards by one each time.

Spot the Error

Question 1
A Total ← 0
B FOR Count = 1 TO 5
C Total ← Total + Count
D NEXT Count
E OUTPUT Total
Line B — The start value of a FOR loop is given with the assignment arrow, not an equals sign. It should be FOR Count ← 1 TO 5.
Question 2
A FOR Count ← 1 TO 5
B OUTPUT Count
C NEXT Counter
D OUTPUT "Done"
Line C — NEXT must name the same loop variable that the FOR line uses. The loop variable is Count, so it should be NEXT Count.
Question 3
A FOR Num ← 1 TO 4
B OUTPUT Num * 2
C ENDFOR
Line C — Cambridge pseudocode ends a FOR loop with NEXT followed by the loop variable, not ENDFOR. It should be NEXT Num.
Question 4
A Total ← 0
B FOR Count ← 1 TO 4
C OUTPUT Count
D Count ← Count + 1
E NEXT Count
F OUTPUT Total
Line D — The loop variable goes up automatically, so it must not be changed by hand inside the loop. This line also means Total is never added to. It should be Total ← Total + Count.
Question 5
A Total ← 0
B FOR Count ← 1 TO 10 STEP 2
C Total ← Total + Count
D NEXT
E OUTPUT Total
Line D — NEXT must be followed by the name of the loop variable. It should be NEXT Count.

Student with a class code? Join your class →