← IGCSE Computer Science Paper 2

Common array mistakes in pseudocode

Typical bugs: loop limits not matching ARRAY[l:u], swapped row and column indexes, a total not reset to 0, or the wrong data type stored. Check bounds, index order and starting values.

Understanding Common array mistakes in pseudocode in IGCSE Computer Science Paper 2

What it does: The loop limits must match the declaration exactly. Starting at 1 would skip element 0 and the loop would also be wrong at the top end. If Total is not reset to 0 first, it keeps an old value and the answer is too large. Setting the starting value fixes this. The upper bound is 30. Index 31 does not exist, so TO 31 causes an index out of range error. Every element must hold the declared data type. A string cannot be stored in an INTEGER array. A 2D array is always written Grid[Row, Column]. Swapping them reads a different cell and can go outside the declared bounds.

Common mistakes: The array starts at index 0, so a loop starting at 1 skips D[0] and the total is too small. It should be FOR i ← 0 TO 6. The loop uses index 0, but the declaration starts at 1, so T[0] is out of range. The declaration should be ARRAY[0:4].

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
DECLARE Scores : ARRAY[1:30] OF INTEGER. Which loop header visits every element safely?
FOR i ← 1 TO 30FOR i ← 1 TO 31
Matches
DECLARE Names : ARRAY[1:5] OF STRING Names[1] ← 42
↓
A number is stored in a STRING array. Each element must hold the declared data type, so store text such as "Ava" instead.
Applying
Meanings
Term
common array mistakes
Meaning
Typical bugs: loop limits not matching ARRAY[l:u], swapped row and column indexes, a total not reset to 0, or the wrong data type stored. Check bounds, index order and starting values.
Practice
DECLARE Marks : ARRAY[1:30] OF INTEGER
Testing
Gaps
FOR i ← 1 TO
Check Answer
Spots
2Total ← 0
3FOR i ← 1 TO 6

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

The 'Kangaroo Rat' badge — Speed Typer, 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. DECLARE Scores : ARRAY[1:30] OF INTEGER. Which loop header visits every element safely?
A. FOR i ← 1 TO 30 ✓
B. FOR i ← 1 TO 31
The upper bound is 30. Index 31 does not exist, so TO 31 causes an index out of range error.
2. DECLARE Names : ARRAY[0:9] OF STRING. Which loop header reaches every element?
A. FOR i ← 0 TO 9 ✓
B. FOR i ← 1 TO 9
The lower bound is 0, so the loop must start at 0. Starting at 1 skips Names[0].
3. The array is ARRAY[0:9]. What is the problem with FOR i ← 1 TO 10?
A. There is no problem because it still runs 10 times
B. It skips index 0 and goes out of range at index 10 ✓
Running the right number of times is not enough. The limits must match the declared bounds, 0 and 9.
4. Grid is ARRAY[1:3, 1:5] (3 rows, 5 columns). Which reads row 2, column 4?
A. Grid[4, 2]
B. Grid[2, 4] ✓
The row index comes first, then the column index. Grid[4, 2] asks for row 4, which does not exist.
5. DECLARE Marks : ARRAY[1:5] OF INTEGER. Which statement is valid?
A. Marks[1] ← 87 ✓
B. Marks[1] ← "eighty-seven"
Every element must hold the declared data type. A string cannot be stored in an INTEGER array.

Match the Pairs

FOR Index ← 1 TO 31 (array is ARRAY[1:30]) → Loop limit goes past the upper bound, so the last pass gives an index out of range error
Grid[Column, Row] (array is ARRAY[1:3, 1:5]) → Row and column indexes are swapped, so the wrong element or an out of range index is used
A loop that fills ARRAY[0:9] must start at the lower bound of 0, not 1 → FOR Index ← 0 TO 9
A running total must be set back to 0 before the loop that adds up the elements → Total ← 0 FOR Index ← 1 TO 30 Total ← Total + Scores[Index] NEXT Index
DECLARE Names : ARRAY[1:5] OF STRING Names[1] ← 42 → A number is stored in a STRING array. Each element must hold the declared data type, so store text such as "Ava" instead.
DECLARE Marks : ARRAY[0:9] OF INTEGER FOR Index ← 1 TO 10 Marks[Index] ← 0 NEXT Index → The loop starts at 1 and ends at 10, but the array bounds are 0 to 9. It skips element 0 and index 10 is out of range. Use FOR Index ← 0 TO 9.

Key Term

common array mistakes
Typical bugs: loop limits not matching ARRAY[l:u], swapped row and column indexes, a total not reset to 0, or the wrong data type stored. Check bounds, index order and starting values.

Fill in the Blanks

1. DECLARE Score : ARRAY[1:30] OF INTEGER FOR i ← 1 TO 30 NEXT i
Hint: Type the final loop value so it matches the upper bound in the declaration and never goes past it.
2. DECLARE Name : ARRAY[0:9] OF STRING FOR Index ← 0 TO 9 NEXT Index
Hint: Type the loop start value so it matches this array's lower bound, so no element is skipped.
3. DECLARE Grid : ARRAY[1:3,1:5] OF INTEGER FOR Row ← 1 TO 3 Grid[Row, 2] ← 0
Hint: Type the variable that goes in the first index position, which selects the row.
4. Total ← 0 FOR i ← 1 TO 10 Total ← Total + Mark[i]
Hint: Type the variable that must be set back to its starting value before the loop adds anything.
5. DECLARE Price : ARRAY[1:5] OF REAL Price[1] ← 4.5
Hint: Type the data type that can store decimal numbers like the value assigned below.

Spot the Error

Question 1
A DECLARE D:ARRAY[0:6] OF REAL
B Total ← 0
C FOR i ← 1 TO 6
D Total ← Total + D[i]
E NEXT i
F OUTPUT Total
Line C — The array starts at index 0, so a loop starting at 1 skips D[0] and the total is too small. It should be FOR i ← 0 TO 6.
Question 2
A DECLARE T:ARRAY[1:4] OF REAL
B FOR i ← 0 TO 4
C T[i] ← 0
D NEXT i
Line A — The loop uses index 0, but the declaration starts at 1, so T[0] is out of range. The declaration should be ARRAY[0:4].
Question 3
A DECLARE N:ARRAY[1:5] OF CHAR
B N[1] ← 12.5
C N[2] ← 7.25
D OUTPUT N[1] + N[2]
Line A — The array stores decimal numbers, but it is declared as CHAR, so the wrong data type is used and the sum makes no sense. It should be OF REAL.
Question 4
A DECLARE S:ARRAY[1:30] OF REAL
B Total ← 0
C FOR i ← 1 TO 31
D Total ← Total + S[i]
E NEXT i
Line C — The array only has indexes 1 to 30, so the loop reaches S[31], which is out of range. It should be FOR i ← 1 TO 30.
Question 5
A // G is ARRAY[1:3, 1:4]
B FOR Row ← 1 TO 3
C FOR Col ← 1 TO 5
D G[Row, Col] ← 0
E NEXT Col
F NEXT Row
Line C — G has only 4 columns, so the inner loop must stop at 4. Going to 5 uses a column that does not exist. It should be FOR Col ← 1 TO 4.

Student with a class code? Join your class →