← IGCSE Computer Science Paper 2

Count-controlled loop: FOR … TO … NEXT

A count-controlled loop. It repeats the indented statements once for each value of Index, from 1 up to 30, going up by 1 each time. NEXT Index closes the loop.

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

What it does: The OUTPUT line is indented between FOR and NEXT, so it is the loop body and runs once for each value of Index. Index starts at 1, increases by 1 each time round and stops after 30, which gives 30 repeats. Cambridge pseudocode writes the start with the assignment arrow: FOR Index ← 1 TO 30. There is no DO. A FOR ... TO ... NEXT loop repeats a set number of times, so it is count-controlled. A WHILE loop repeats while a condition is true. The loop variable name after NEXT must match the one after FOR, otherwise the loop is not closed correctly.

Common mistakes: The array index must use the loop variable Index, which changes each time round. Count is not the loop variable. It should be Score[Index] ← 0. The closing square bracket is missing. The statement inside the loop should be OUTPUT Mark[Index].

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 449–458) and word search (Modules 439–458).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line correctly starts a loop that runs 30 times using Index?
FOR Index ← 1 TO 30FOR Index = 1 TO 30 DO
Matches
FOR Index ← 1 TO 30 OUTPUT Index NEXT Count
↓
NEXT uses a different name (Count) from the loop variable Index. NEXT must repeat the same variable name as the FOR line, so it should be NEXT Index.
Applying
Meanings
Term
FOR Index ← 1 TO 30
Meaning
A count-controlled loop. It repeats the indented statements once for each value of Index, from 1 up to 30, going up by 1 each time. NEXT Index closes the loop.
Practice
FOR Index ← 1 TO 30
Testing
Gaps
Index ← 1 TO 30
Check Answer
Spots
1FOR Index ← 1 TO 30
2 Score[Count] ← 0

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 starts a loop that runs 30 times using Index?
A. FOR Index ← 1 TO 30 ✓
B. FOR Index = 1 TO 30 DO
Cambridge pseudocode writes the start with the assignment arrow: FOR Index ← 1 TO 30. There is no DO.
2. Which line correctly closes the loop that began FOR Index ← 1 TO 30?
A. ENDFOR Index
B. NEXT Index ✓
A FOR loop is closed with NEXT followed by the same loop variable name: NEXT Index.
3. In FOR Index ← 1 TO 30, how does Index change after each repeat?
A. It increases by 1 each time ✓
B. It stays at 1 until the loop ends
Index goes 1, 2, 3 ... up to 30, increasing by 1 on each repeat of the loop.
4. Where do the statements that repeat belong?
A. Written after NEXT Index
B. Indented between FOR and NEXT ✓
The repeated statements sit between the FOR line and the NEXT line, indented. Statements after NEXT run only once, after the loop finishes.
5. Which NEXT line matches FOR Index ← 1 TO 30?
A. NEXT Index ✓
B. NEXT Count
The variable name after NEXT must repeat the loop variable name. Here that name is Index.

Match the Pairs

FOR Index ← 1 TO 30 → Starts a loop that repeats the indented statements once for each value of Index, from 1 up to 30
NEXT Index → Closes the loop, adds 1 to Index and goes back to the FOR line
The statements inside the loop are indented so you can see which lines repeat on each pass → FOR Index ← 1 TO 30 OUTPUT Index NEXT Index
A loop that runs 30 times, with Index going up by 1 each time, from 1 to 30 → FOR Index ← 1 TO 30
FOR Index ← 1 TO 30 OUTPUT Index NEXT Count → NEXT uses a different name (Count) from the loop variable Index. NEXT must repeat the same variable name as the FOR line, so it should be NEXT Index.
FOR Index ← 1 TO 30 OUTPUT Index NEXT Index → The statement inside the loop is not indented. The body should be indented, as in ' OUTPUT Index', so it is clear which lines repeat.

Key Term

FOR Index ← 1 TO 30
A count-controlled loop. It repeats the indented statements once for each value of Index, from 1 up to 30, going up by 1 each time. NEXT Index closes the loop.

Fill in the Blanks

1. FOR Index ← 1 TO 30 Scores[Index] ← 0 NEXT Index
Hint: Type the keyword that starts a count-controlled loop.
2. FOR Index ← 1 TO 30 OUTPUT Scores[Index] NEXT Index
Hint: Type the keyword that sits between the start value and the end value.
3. FOR Index ← 1 TO 30 OUTPUT Scores[Index] NEXT Index
Hint: Type the loop variable name that NEXT repeats to close the loop.
4. FOR Index ← 1 TO 30 Total ← Total + Scores[Index] NEXT Index
Hint: Type the keyword that closes the loop and moves on to the next value.
5. FOR Index ← 1 TO 30 Scores[Index] ← 0 NEXT Index
Hint: Type the assignment symbol that gives the loop variable its starting value.

Spot the Error

Question 1
A FOR Index ← 1 TO 30
B Score[Count] ← 0
C NEXT Index
Line B — The array index must use the loop variable Index, which changes each time round. Count is not the loop variable. It should be Score[Index] ← 0.
Question 2
A FOR Index ← 1 TO 10
B OUTPUT Mark[Index
C NEXT Index
Line B — The closing square bracket is missing. The statement inside the loop should be OUTPUT Mark[Index].
Question 3
A FOR Index ← 1 TO 5
B INPUT Num[Index]
C NEXT Num
Line C — NEXT must repeat the loop variable name from the FOR line. Num is the array, not the loop variable. It should be NEXT Index.
Question 4
A Total ← 0
B FOR Index ← 1 TO 30
C Total ← Total + Mark[Index]
D ENDFOR
Line D — In IGCSE pseudocode a FOR loop is closed with NEXT followed by the loop variable, not ENDFOR. It should be NEXT Index.
Question 5
A FOR Index = 1 TO 30
B Mark[Index] ← 0
C NEXT Index
Line A — The loop variable is given its start value with the assignment arrow ←, not =. It should be FOR Index ← 1 TO 30.

Student with a class code? Join your class →