← IGCSE Computer Science Paper 2

FOR…TO…NEXT count-controlled loop

A count-controlled loop that repeats the indented lines end - start + 1 times, adding 1 to the counter each time. It is closed by NEXT Count, which names the same counter.

Understanding FOR…TO…NEXT count-controlled loop in IGCSE Computer Science Paper 2

What it does: 1 TO 5 gives 5 - 1 + 1 = 5 repeats. The indented OUTPUT is the loop body and NEXT Count closes the loop. 7 - 3 + 1 = 5, so Num takes the values 3, 4, 5, 6, 7. The counter goes up by 1 each time and NEXT Num names the same counter. The loop runs end - start + 1 times, so 10 - 1 + 1 = 10. 7 - 3 + 1 = 5. Num takes the values 3, 4, 5, 6 and 7. Without STEP, the counter increases by 1 on every repeat.

Common mistakes: NEXT must name the same counter that FOR started with. It should be NEXT Count, not NEXT Total. A FOR loop gives the counter its start value with the assignment arrow <-, not =. It should be FOR Num <- 1 TO 3.

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 369–378) and word search (Modules 358–378).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line correctly closes this loop? FOR Count <- 1 TO 10
NEXT CountENDFOR Count
Matches
FOR Count <- 1 TO 10 OUTPUT Count NEXT Counter
↓
NEXT names a different variable (Counter) from the one in the FOR line (Count). The counter names must match.
Applying
Meanings
Term
FOR Count <- 1 TO 10
Meaning
A count-controlled loop that repeats the indented lines end - start + 1 times, adding 1 to the counter each time. It is closed by NEXT Count, which names the same counter.
Practice
FOR Count ← 1 TO 5
Testing
Gaps
FOR Count 1 TO 10
Check Answer
Spots
2 OUTPUT Count
3NEXT Total

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

The 'Leopard' badge — Savannah Perfectionist, 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 line correctly closes this loop? FOR Count <- 1 TO 10
A. NEXT Count ✓
B. ENDFOR Count
Cambridge pseudocode closes a FOR loop with NEXT followed by the same counter name.
2. How many times does this loop run? FOR Count <- 1 TO 10
A. 10 times ✓
B. 9 times
The loop runs end - start + 1 times, so 10 - 1 + 1 = 10.
3. How many times does this loop run? FOR Num <- 3 TO 7
A. 5 times ✓
B. 4 times
7 - 3 + 1 = 5. Num takes the values 3, 4, 5, 6 and 7.
4. Which NEXT line matches this loop? FOR Index <- 1 TO 5
A. NEXT Count
B. NEXT Index ✓
The name after NEXT must be the same counter used in the FOR line.
5. By how much does the counter change each time round a FOR loop with no STEP?
A. It goes up by 2
B. It goes up by 1 ✓
Without STEP, the counter increases by 1 on every repeat.

Match the Pairs

FOR Count <- 1 TO 10 → Starts a loop that repeats the indented lines 10 times, with Count going 1, 2, 3 ... 10
NEXT Count → Ends the FOR loop and names the same counter that the FOR line used
A loop that must run exactly 5 times, with the counter going 1 to 5 → FOR Count <- 1 TO 5 OUTPUT Count NEXT Count
A loop from 3 to 7 runs 5 times because end - start + 1 = 5 → FOR Num <- 3 TO 7 OUTPUT Num NEXT Num
FOR Count <- 1 TO 10 OUTPUT Count NEXT Counter → NEXT names a different variable (Counter) from the one in the FOR line (Count). The counter names must match.
FOR Count <- 1 TO 10 OUTPUT Count → The loop has no NEXT Count line, so it is never closed.

Key Term

FOR Count <- 1 TO 10
A count-controlled loop that repeats the indented lines end - start + 1 times, adding 1 to the counter each time. It is closed by NEXT Count, which names the same counter.

Fill in the Blanks

1. FOR Count <- 1 TO 10 OUTPUT Count NEXT Count
Hint: Type the assignment operator that gives the counter its starting value.
2. FOR Count <- 1 TO 10 OUTPUT Count NEXT Count
Hint: Type the keyword that separates the start value from the end value.
3. FOR Count <- 1 TO 5 OUTPUT "Hello" NEXT Count
Hint: Type the keyword that closes the FOR loop.
4. FOR Count <- 1 TO 10 OUTPUT Count * 2 NEXT Count
Hint: Type the counter variable name that must match the one in the FOR line.
5. FOR Num <- 1 TO 5 OUTPUT "Go" NEXT Num
Hint: Type the end value that makes this loop run five times when it starts at 1.

Spot the Error

Question 1
A FOR Count <- 1 TO 5
B OUTPUT Count
C NEXT Total
Line C — NEXT must name the same counter that FOR started with. It should be NEXT Count, not NEXT Total.
Question 2
A FOR Num = 1 TO 3
B OUTPUT Num * 2
C NEXT Num
Line A — A FOR loop gives the counter its start value with the assignment arrow <-, not =. It should be FOR Num <- 1 TO 3.
Question 3
A Total <- 0
B FOR Count <- 1 UNTIL 4
C Total <- Total + Count
D NEXT Count
E OUTPUT Total
Line B — A FOR loop uses the keyword TO between the start and end values. UNTIL belongs to REPEAT...UNTIL. It should be FOR Count <- 1 TO 4.
Question 4
A FOR Count <- 1 TO 6
B OUTPUT Count
C ENDFOR
Line C — Cambridge pseudocode closes a FOR loop with NEXT followed by the counter name, not ENDFOR. It should be NEXT Count.
Question 5
A Sum <- 0
B FOR Index <- TO 10
C INPUT Mark
D Sum <- Sum + Mark
E NEXT Index
Line B — The FOR line needs a start value after <-. It should be FOR Index <- 1 TO 10, so the loop runs 10 times.

Student with a class code? Join your class →