← IGCSE Computer Science Paper 2

FOR ... TO ... NEXT

Repeats the statements below once for each whole number from 1 to 30 inclusive. Index is an INTEGER that changes automatically each time. Close the loop with NEXT Index.

Understanding FOR ... TO ... NEXT in IGCSE Computer Science Paper 2

What it does: Count goes 1, 2, 3, 4, 5 without any Count ← Count + 1 line, because the FOR loop changes it automatically. The FOR loop counts in whole numbers, so the variable holding the count is declared with the INTEGER data type. The loop runs once for each integer from 1 to 30 inclusive, so it repeats 30 times. A FOR loop in Cambridge pseudocode ends with NEXT followed by the same identifier. There is no ENDFOR. The FOR loop increases the loop variable by itself on every repeat, so you do not add 1 yourself. Assignment uses the arrow ←. The = sign is used for comparison, not for giving the loop variable its start value.

Common mistakes: A FOR loop gives its loop variable a starting value with the assignment arrow ←, not =. It should be FOR Index ← 1 TO 30. NEXT must repeat the same identifier that follows FOR. The loop variable is Count, so the line 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 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 FOR loop runs its statements exactly 30 times?
FOR Index ← 1 TO 29FOR Index ← 1 TO 30
Matches
FOR Index ← 1 TO 30 OUTPUT Index NEXT Count
↓
NEXT uses a different identifier from the FOR line. It must repeat the same loop variable, so it should be NEXT Index.
Applying
Meanings
Term
FOR Index ← 1 TO 30
Meaning
Repeats the statements below once for each whole number from 1 to 30 inclusive. Index is an INTEGER that changes automatically each time. Close the loop with NEXT Index.
Practice
DECLARE Index : INTEGER
Testing
Gaps
Index ← 1 TO 30
Check Answer
Spots
1Total ← 0
2FOR Index = 1 TO 30

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

The 'Platinum Fox' badge — Tundra Legend, 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 FOR loop runs its statements exactly 30 times?
A. FOR Index ← 1 TO 30 ✓
B. FOR Index ← 1 TO 29
The loop runs once for each integer from 1 to 30 inclusive, so it repeats 30 times.
2. Which line correctly ends a loop that starts with FOR Count ← 1 TO 10?
A. NEXT Count ✓
B. ENDFOR Count
A FOR loop in Cambridge pseudocode ends with NEXT followed by the same identifier. There is no ENDFOR.
3. The loop variable Index in FOR Index ← 1 TO 30 changes ...
A. only when you write Index ← Index + 1 inside the loop
B. automatically each time round the loop ✓
The FOR loop increases the loop variable by itself on every repeat, so you do not add 1 yourself.
4. What data type should the loop variable in a FOR loop be?
A. INTEGER ✓
B. STRING
The loop counts through whole numbers, so the loop variable must be an INTEGER.
5. Which pair of lines is written correctly?
A. FOR Index ← 1 TO 5 ... NEXT Count
B. FOR Index ← 1 TO 5 ... NEXT Index ✓
The identifier after NEXT must be the same as the loop variable after FOR.

Match the Pairs

FOR Index ← 1 TO 30 → Starts a loop that repeats the statements below once for each whole number from 1 to 30 inclusive
NEXT Index → Ends the FOR loop and names the same loop variable that the FOR line used
The loop variable changes by itself, so you never write a line to add 1 to it → FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
The loop variable is an INTEGER, so it must be declared as one before the loop → DECLARE Index : INTEGER FOR Index ← 1 TO 30 OUTPUT Index NEXT Index
FOR Index ← 1 TO 30 OUTPUT Index NEXT Count → NEXT uses a different identifier from the FOR line. It must repeat the same loop variable, so it should be NEXT Index.
FOR Index = 1 TO 30 OUTPUT Index NEXT Index → The loop variable is given its start value with = instead of the assignment arrow. It should be FOR Index ← 1 TO 30.

Key Term

FOR Index ← 1 TO 30
Repeats the statements below once for each whole number from 1 to 30 inclusive. Index is an INTEGER that changes automatically each time. Close the loop with NEXT Index.

Fill in the Blanks

1. FOR Index ← 1 TO 30 OUTPUT Index NEXT Index
Hint: Type the keyword that starts a count-controlled loop.
2. FOR Index ← 1 TO 30 OUTPUT Index NEXT Index
Hint: Type the keyword that separates the start value from the end value.
3. FOR Number ← 1 TO 10 OUTPUT Number * 2 NEXT Number
Hint: Type the keyword that closes the FOR loop.
4. FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
Hint: Type the loop variable name, repeated after the closing keyword.
5. FOR Index ← 1 TO 30 OUTPUT Index NEXT Index
Hint: Type the assignment symbol that gives the loop variable its start value.

Spot the Error

Question 1
A Total ← 0
B FOR Index = 1 TO 30
C Total ← Total + Index
D NEXT Index
Line B — A FOR loop gives its loop variable a starting value with the assignment arrow ←, not =. It should be FOR Index ← 1 TO 30.
Question 2
A FOR Count ← 1 TO 5
B OUTPUT "Hello"
C OUTPUT Count
D NEXT Counter
Line D — NEXT must repeat the same identifier that follows FOR. The loop variable is Count, so the line should be NEXT Count.
Question 3
A Sum ← 0
B FOR Num ← 1 UNTIL 20
C Sum ← Sum + Num
D NEXT Num
Line B — The end value of a FOR loop is introduced with TO, not UNTIL. UNTIL belongs to REPEAT loops. It should be FOR Num ← 1 TO 20.
Question 4
A DECLARE Index : INTEGER
B FOR Index ← 1.5 TO 30
C OUTPUT Index
D NEXT Index
Line B — The loop variable is an INTEGER, so it must start at a whole number. 1.5 is a REAL. It should be FOR Index ← 1 TO 30.
Question 5
A Total ← 0
B FOR Index ← 1 TO 10
C Total ← Total + Number
D NEXT Index
E OUTPUT Total
Line C — Number has never been set. The loop variable is Index, which changes automatically each time round, so the line should be Total ← Total + Index.

Student with a class code? Join your class →