← IGCSE Computer Science Paper 2

Pseudocode FOR ... TO ... NEXT loop

A count-controlled loop that repeats the indented statements a fixed number of times, with Count going from 1 to 10. NEXT Count closes the loop and moves Count up by 1.

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

What it does: The OUTPUT statement is indented inside the loop, so it repeats 3 times, showing 1, 2 and 3. NEXT Count closes the loop. Counting from 1 to 10 gives 10 repeats. The variable after NEXT (Number) matches the one in the FOR line. A FOR loop uses TO to give the end value. UNTIL belongs to REPEAT ... UNTIL, not FOR. Count takes the values 1, 2, 3 ... 10, and both the start and end values are included. That makes 10 repetitions. A FOR loop counts upwards from the start value to the end value. The start value must be the smaller one.

Common mistakes: NEXT must use the same variable as the FOR line. The loop counter is Count, so the line should be NEXT Count. 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 10.

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 123–134) and word search (Modules 123–145).

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 repeats 5 times in Cambridge pseudocode?
FOR Count ← 1 TO 5FOR Count ← 1 UNTIL 5
Matches
FOR Count ← 1 TO 5 OUTPUT Count NEXT i
↓
NEXT uses a different variable name (i) from the one in the FOR line (Count). It should be NEXT Count.
Applying
Meanings
Term
FOR Count ← 1 TO 10
Meaning
A count-controlled loop that repeats the indented statements a fixed number of times, with Count going from 1 to 10. NEXT Count closes the loop and moves Count up by 1.
Practice
FOR Count ← 1 TO 5
Testing
Gaps
Count ← 1 TO 10
Check Answer
Spots
3 Total ← Total + Count
4NEXT Total

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

The 'Viperfish' badge — Deep Debugger, 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 repeats 5 times in Cambridge pseudocode?
A. FOR Count ← 1 UNTIL 5
B. FOR Count ← 1 TO 5 ✓
A FOR loop uses TO to give the end value. UNTIL belongs to REPEAT ... UNTIL, not FOR.
2. Which line correctly closes the loop FOR Count ← 1 TO 10?
A. NEXT Count ✓
B. ENDFOR Count
Cambridge pseudocode closes a FOR loop with NEXT followed by the same variable. ENDFOR is not used.
3. A FOR loop starts with FOR Count ← 1 TO 10. What does the NEXT Count line do?
A. It adds 1 to Count and goes back to the top of the loop ✓
B. It stops the loop straight away
NEXT Count marks the end of the loop body and moves Count up by 1. The loop only ends once Count passes the end value.
4. How many times does the loop body run? FOR Count ← 1 TO 10
A. 9 times
B. 10 times ✓
Count takes the values 1, 2, 3 ... 10, and both the start and end values are included. That makes 10 repetitions.
5. Which FOR loop is written correctly?
A. FOR Count ← 1 TO 10 OUTPUT Count NEXT Count ✓
B. FOR Count ← 1 TO 10 OUTPUT Count NEXT Total
The variable after NEXT must be the same as the loop variable after FOR. Here both should be Count.

Match the Pairs

FOR Count ← 1 TO 5 → Starts a count-controlled loop where Count begins at 1 and goes up to 5, so the loop body repeats 5 times
NEXT Count → Marks the end of the FOR loop and adds 1 to Count before the loop checks whether to repeat again
A FOR loop that counts from 1 to 3 and outputs the counter each time, with the loop body indented → FOR Count ← 1 TO 3 OUTPUT Count NEXT Count
A FOR loop that repeats an action exactly 10 times, using the same variable name after NEXT → FOR Number ← 1 TO 10 OUTPUT "Hello" NEXT Number
FOR Count ← 1 TO 5 OUTPUT Count NEXT i → NEXT uses a different variable name (i) from the one in the FOR line (Count). It should be NEXT Count.
FOR Count ← 1 TO 5 OUTPUT Count NEXT Count → The statement inside the loop is not indented. The loop body should be indented, e.g. 3 spaces before OUTPUT Count.

Key Term

FOR Count ← 1 TO 10
A count-controlled loop that repeats the indented statements a fixed number of times, with Count going from 1 to 10. NEXT Count closes the loop and moves Count up by 1.

Fill in the Blanks

1. FOR Count ← 1 TO 10 OUTPUT Count NEXT Count
Hint: Type the keyword that starts a count-controlled loop.
2. FOR Count ← 1 TO 10 OUTPUT Count NEXT Count
Hint: Type the keyword that closes the loop and moves the counter up by one.
3. FOR Num ← 1 TO 5 OUTPUT "Hi" NEXT Num
Hint: Type the keyword that separates the start value from the end value.
4. FOR Count ← 1 TO 3 // repeat 3 times OUTPUT "Go" NEXT Count
Hint: Type the end value of the counter that matches the comment.
5. FOR Num ← 1 TO 4 OUTPUT Num * 2 NEXT Num
Hint: Type the same counter variable that the loop started with.

Spot the Error

Question 1
A Total ← 0
B FOR Count ← 1 TO 5
C Total ← Total + Count
D NEXT Total
E OUTPUT Total
Line D — NEXT must use the same variable as the FOR line. The loop counter is Count, so the line should be NEXT Count.
Question 2
A FOR Count ← 1 UNTIL 10
B OUTPUT Count
C NEXT Count
Line A — 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 10.
Question 3
A Total ← 0
B FOR Number ← 5 TO 1
C INPUT Mark
D Total ← Total + Mark
E NEXT Number
Line B — A FOR loop counts up from the start value to the end value. With 5 TO 1 the start is bigger than the end, so the loop would not run. It should be FOR Number ← 1 TO 5.
Question 4
A OUTPUT "Start"
B FOR Count ← 1 TO 3
C OUTPUT Counter * 2
D NEXT Count
Line C — The loop variable is Count, so the body must use Count. Counter is a different variable that has no value. It should be OUTPUT Count * 2.
Question 5
A Total ← 0
B FOR Count ← 1 TO 10
C Total = Total + Count
D NEXT Count
Line C — Cambridge pseudocode uses the assignment arrow ←, not =. The line should be Total ← Total + Count.

Student with a class code? Join your class →