← IGCSE Computer Science Paper 2

Looping through an array with FOR (7d)

A loop whose counter is the array index. Inside it, Marks[Index] picks each element in turn, so the loop visits every item from position 1 to 10 once.

Understanding Looping through an array with FOR (7d) in IGCSE Computer Science Paper 2

What it does: INPUT stores each typed value into Marks[Index], so the loop fills positions 1 to 10 one at a time. The counter goes through every position from 1 to 10, so each element of Marks is output exactly once. Cambridge arrays usually start at index 1, so a 10-item array has indexes 1 to 10. Starting at 0 would refer to an element that does not exist. Both the start value 1 and the end value 10 are included, so Index takes 10 values. Cambridge pseudocode closes a FOR loop with NEXT followed by the counter name. ENDFOR is not used.

Common mistakes: A FOR loop sets its counter with the assignment arrow ←, not =. It should be FOR Index ← 1 TO 10. The end value of a FOR loop follows the keyword TO, not UNTIL. UNTIL belongs to REPEAT loops. It should be FOR Index ← 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 275–285) and word search (Modules 275–295).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which loop header visits every element of a 10-item array Marks, starting at index 1?
FOR Index ← 1 TO 10FOR Index ← 0 TO 10
Matches
FOR Index ← 1 TO 10 OUTPUT Marks[10] NEXT Index
↓
The index is fixed at 10, so the same element is output ten times instead of using Index to visit each element.
Applying
Meanings
Term
FOR Index ← 1 TO 10
Meaning
A loop whose counter is the array index. Inside it, Marks[Index] picks each element in turn, so the loop visits every item from position 1 to 10 once.
Practice
FOR Index ← 1 TO 10
Testing
Gaps
FOR Index ← 1 10
Check Answer
Spots
1FOR Index = 1 TO 10
2 INPUT Marks[Index]

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

The 'Meerkat' badge — Communicator, 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 loop header visits every element of a 10-item array Marks, starting at index 1?
A. FOR Index ← 1 TO 10 ✓
B. FOR Index ← 0 TO 10
Cambridge arrays usually start at index 1, so a 10-item array has indexes 1 to 10. Starting at 0 would refer to an element that does not exist.
2. Inside FOR Index ← 1 TO 10, which line outputs the current element of Marks?
A. OUTPUT Marks[10]
B. OUTPUT Marks[Index] ✓
Marks[Index] changes each time round the loop, so every element is output. Marks[10] always outputs the 10th element.
3. Which statement about the loop FOR Index ← 1 TO 10 is true?
A. Index is the value stored in the array
B. Index is the counter and also the position in the array ✓
Index counts 1, 2, 3 ... 10 and is used inside the square brackets to choose a position. The value stored at that position is Marks[Index].
4. Which loop fills an array with 10 marks typed by the user?
A. FOR Index ← 1 TO 10 INPUT Marks[Index] NEXT Index ✓
B. FOR Index ← 1 TO 10 INPUT Marks NEXT Index
Each INPUT must store the value in a particular element, so you write Marks[Index]. Without the index, you do not say which element receives the value.
5. How many times does the body of FOR Index ← 1 TO 10 run?
A. 10 times ✓
B. 9 times
Both the start value 1 and the end value 10 are included, so Index takes 10 values.

Match the Pairs

FOR Index ← 1 TO 10 → Repeats the loop body once for each array position from 1 to 10, with Index counting up each time
OUTPUT Marks[Index] → Displays the element at the current position, so each pass of the loop shows the next mark
Fill an array by asking the user for a value at each position as the counter moves along → FOR Index ← 1 TO 10 INPUT Marks[Index] NEXT Index
Output every element of the array in order using the loop counter as the index → FOR Index ← 1 TO 10 OUTPUT Marks[Index] NEXT Index
FOR Index ← 1 TO 10 OUTPUT Marks[10] NEXT Index → The index is fixed at 10, so the same element is output ten times instead of using Index to visit each element.
FOR Index ← 0 TO 10 INPUT Marks[Index] NEXT Index → The loop starts at 0 and runs 11 times, but the array has positions 1 to 10, so Marks[0] does not exist.

Key Term

FOR Index ← 1 TO 10
A loop whose counter is the array index. Inside it, Marks[Index] picks each element in turn, so the loop visits every item from position 1 to 10 once.

Fill in the Blanks

1. FOR Index ← 1 TO 10 INPUT Marks[Index] NEXT Index
Hint: Type the keyword that joins the start value and the end value of the loop.
2. FOR Index ← 1 TO 10 OUTPUT Marks[Index] NEXT Index
Hint: Type the keyword that displays each array element on the screen.
3. FOR Index ← 1 TO 10 INPUT Marks[Index] NEXT Index
Hint: Type the loop counter name that picks the current element.
4. DECLARE Marks : ARRAY[1:10] OF INTEGER FOR Index ← 1 TO 10 INPUT Marks[Index]
Hint: Type the last index so the loop reaches every element of the array.
5. FOR Index ← 1 TO 10 OUTPUT Marks[Index] NEXT Index
Hint: Type the keyword that ends the loop body and moves the counter on.

Spot the Error

Question 1
A FOR Index = 1 TO 10
B INPUT Marks[Index]
C NEXT Index
Line A — A FOR loop sets its counter with the assignment arrow ←, not =. It should be FOR Index ← 1 TO 10.
Question 2
A FOR Index ← 1 UNTIL 10
B OUTPUT Marks[Index]
C NEXT Index
Line A — The end value of a FOR loop follows the keyword TO, not UNTIL. UNTIL belongs to REPEAT loops. It should be FOR Index ← 1 TO 10.
Question 3
A Sum ← 0
B FOR Index ← 1 TO 10
C Sum ← Sum + Marks[1]
D NEXT Index
Line C — Marks[1] always picks the first element, so every pass adds the same mark. Use the loop counter: Marks[Index] so each element is visited in turn.
Question 4
A FOR Index ← 1 TO 10
B OUTPUT "Enter mark"
C INPUT Marks[Index]
D ENDFOR
Line D — In Cambridge pseudocode a FOR loop ends with NEXT and the counter name, not ENDFOR. It should be NEXT Index.
Question 5
A FOR Index ← 1 TO 10
B OUTPUT Marks(Index)
C NEXT Index
Line B — Array elements are picked with square brackets, not round brackets. It should be OUTPUT Marks[Index].

Student with a class code? Join your class →