← IGCSE Computer Science Paper 2

Writing a complete array program: declare, fill and output

The pattern of a complete array program: declare the array, use a FOR loop to INPUT a value into each element, then use a second FOR loop to OUTPUT every element.

Understanding Writing a complete array program: declare, fill and output in IGCSE Computer Science Paper 2

What it does: The OUTPUT loop uses the same bounds as the INPUT loop and reads each element in turn, here showing a name and its mark. The outer loop picks the row and the inner loop picks each column, so every cell of the grid receives a value. Indentation shows which loop is inside which. The array must be declared first. Then you fill it with INPUT, and only then can you OUTPUT the values that are stored in it. Names are text, so the array needs the data type STRING. An INTEGER array can only hold whole numbers. The loop must match the bounds 1 to 30. Going up to 31 would be an index out of range error.

Common mistakes: Array elements are accessed with square brackets, not round ones. It should be INPUT Pay[i]. A FOR loop in IGCSE pseudocode is closed with NEXT and the loop variable, not ENDFOR. Line 3 should be NEXT i.

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 479–488) and word search (Modules 479–499).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which order shows the correct pattern for a complete array program?
DECLARE the array, FOR loop with INPUT, FOR loop with OUTPUTFOR loop with OUTPUT, FOR loop with INPUT, DECLARE the array
Matches
DECLARE Marks : ARRAY[1:5] OF INTEGER FOR Index ← 1 TO 10 INPUT Marks[Index] NEXT Index
↓
The loop goes up to 10 but the array only has indexes 1 to 5, so it goes out of range. The loop should be FOR Index ← 1 TO 5.
Applying
Meanings
Term
DECLARE, FOR INPUT, FOR OUTPUT
Meaning
The pattern of a complete array program: declare the array, use a FOR loop to INPUT a value into each element, then use a second FOR loop to OUTPUT every element.
Practice
DECLARE Marks : ARRAY[1:5] OF INTEGER
Testing
Gaps
DECLARE Marks : [1:5] OF INTEGER
Check Answer
Spots
2FOR i ← 1 TO 3
3 INPUT Pay(i)

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

The 'Manta Ray' badge — Graceful Coder, 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 order shows the correct pattern for a complete array program?
A. FOR loop with OUTPUT, FOR loop with INPUT, DECLARE the array
B. DECLARE the array, FOR loop with INPUT, FOR loop with OUTPUT ✓
The array must be declared first. Then you fill it with INPUT, and only then can you OUTPUT the values that are stored in it.
2. Which line correctly declares a 1D array to hold 5 student names?
A. DECLARE StudentNames : ARRAY[1:5] OF INTEGER
B. DECLARE StudentNames : ARRAY[1:5] OF STRING ✓
Names are text, so the array needs the data type STRING. An INTEGER array can only hold whole numbers.
3. Which loop correctly fills the Marks array with 5 values typed in by the user?
A. FOR Index ← 1 TO 5 INPUT Marks[Index] NEXT Index ✓
B. FOR Index ← 1 TO 5 OUTPUT Marks[Index] NEXT Index
INPUT reads a value from the user into each element. OUTPUT would only display what is already stored.
4. A program has DECLARE Marks : ARRAY[1:30] OF INTEGER. Which loop header visits every element?
A. FOR Index ← 1 TO 30 ✓
B. FOR Index ← 1 TO 31
The loop must match the bounds 1 to 30. Going up to 31 would be an index out of range error.
5. Which is the best way to write the OUTPUT loop body for the array StudentNames?
A. OUTPUT StudentNames[Index] ✓
B. OUTPUT StudentNames
To show each element you must use the index, such as StudentNames[Index]. Without it you do not output the individual values one by one.

Match the Pairs

DECLARE Marks : ARRAY[1:5] OF INTEGER → Step 1 of the program: create the array before using it, with its bounds and data type.
FOR Index ← 1 TO 5 INPUT Marks[Index] NEXT Index → Step 2 of the program: a loop that fills every element of the array with a value typed in by the user.
After the array is filled, a second FOR loop with the same bounds shows every element on the screen. → FOR Index ← 1 TO 5 OUTPUT Names[Index], Marks[Index] NEXT Index
A 2D grid is filled using a loop inside a loop, with one index for the row and one for the column. → FOR Row ← 1 TO 3 FOR Col ← 1 TO 4 INPUT Grid[Row, Col] NEXT Col NEXT Row
DECLARE Marks : ARRAY[1:5] OF INTEGER FOR Index ← 1 TO 10 INPUT Marks[Index] NEXT Index → The loop goes up to 10 but the array only has indexes 1 to 5, so it goes out of range. The loop should be FOR Index ← 1 TO 5.
FOR Index ← 1 TO 5 INPUT Marks[Index] NEXT Index OUTPUT Marks → OUTPUT Marks does not show each element. A second FOR loop is needed with OUTPUT Marks[Index] to display every element.

Key Term

DECLARE, FOR INPUT, FOR OUTPUT
The pattern of a complete array program: declare the array, use a FOR loop to INPUT a value into each element, then use a second FOR loop to OUTPUT every element.

Fill in the Blanks

1. DECLARE Marks : ARRAY[1:5] OF INTEGER
Hint: Type the keyword that tells the computer this variable holds many values under one name
2. FOR Count ← 1 TO 5 INPUT Marks[Count] NEXT Count
Hint: Type the keyword that reads a value from the user into each element
3. FOR Count ← 1 TO 5 OUTPUT Names[Count] NEXT Count
Hint: Type the loop variable that must match the one in the FOR line
4. FOR Row ← 1 TO 3 FOR Col ← 1 TO 4 INPUT Grid[Row, Col]
Hint: Type the inner loop variable that selects the column of the grid
5. DECLARE Names : ARRAY[1:3] OF STRING FOR Index ← 1 TO 3 OUTPUT Names[Index]
Hint: Type the data type that suits an array of names

Spot the Error

Question 1
A DECLARE Pay:ARRAY[1:3] OF REAL
B FOR i ← 1 TO 3
C INPUT Pay(i)
D NEXT i
Line C — Array elements are accessed with square brackets, not round ones. It should be INPUT Pay[i].
Question 2
A FOR i ← 1 TO 3
B INPUT Fee[i]
C ENDFOR
D FOR i ← 1 TO 3
E OUTPUT Fee[i]
F NEXT i
Line C — A FOR loop in IGCSE pseudocode is closed with NEXT and the loop variable, not ENDFOR. Line 3 should be NEXT i.
Question 3
A DECLARE Pay:ARRAY[1:3] REAL
B FOR i ← 1 TO 3
C INPUT Pay[i]
D NEXT i
Line A — The declaration is missing the keyword OF before the data type. It should be DECLARE Pay:ARRAY[1:3] OF REAL.
Question 4
A DECLARE Grd:ARRAY[1:4] OF CHAR
B FOR i ← 1 TO 5
C INPUT Grd[i]
D NEXT i
Line B — The array's upper bound is 4, so the loop must stop at 4. Going to 5 would cause an index out of range error. It should be FOR i ← 1 TO 4.
Question 5
A FOR i ← 1 TO 3
B INPUT Mark[j]
C NEXT i
D FOR i ← 1 TO 3
E OUTPUT Mark[i]
F NEXT i
Line B — The loop variable is i, but the index uses j, which has no value. The index must be the loop variable, so it should be INPUT Mark[i].

Student with a class code? Join your class →