Revision Notes
Cambridge O Level Computer Science (2210): Arrays – Revision Notes
Revision notes for Cambridge O Level Computer Science 2210 section 8.2: declaring 1D and 2D arrays, indexes, loops and nested loops, common patterns and a self-test.
- Subject
- Computer Science
- Level
- O LEVELS
- Topic
- Topic 8 – Programming
- Author
- Marlbridge Academic Team
- Updated
- Reviewed by
- Harris Khan (what this means)
Aligned to Cambridge O Level Computer Science (2210), 2026-2028. Official specification .
Syllabus page (what it covers and how it is assessed): Cambridge O Level Computer Science.
Syllabus points this page covers
2210
- 8.2 Arrays
This page covers 1 of the 3 subtopics in topic 8, Programming.
Found an error? Report a correction.
Need help with this topic? Request a free trial class for O Level Computer Science (2210).
Condensed notes for syllabus section 8.2, Arrays. For the full explanations and a model answer, use the Arrays study guide.
Syllabus checklist
- Declare and use one-dimensional (1D) and two-dimensional (2D) arrays.
- Understand the use of arrays, including variables as indexes.
- Write values into, and read values from, an array using iteration, including nested iteration.
- The first index can be zero or one.
Key terms
| Term | Definition |
|---|---|
| Array | A fixed-length structure holding elements of the same data type under one name |
| Element | One value stored in an array |
| Index | The position number used to find an element |
| Lower bound | The index of the first element |
| Upper bound | The index of the last element |
| 1D array | A single list of elements |
| 2D array | A table of elements with rows and columns |
| Nested iteration | A loop inside another loop |
Declaring arrays
DECLARE Marks : ARRAY[1:30] OF INTEGER
DECLARE Names : ARRAY[1:30] OF STRING
DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
- Square brackets hold the bounds as
lower:upper. - In a 2D array the first range is the rows and the second is the columns.
- Number of elements = (upper − lower + 1) for each dimension, multiplied together.
| Declaration | Elements |
|---|---|
ARRAY[1:10] |
10 |
ARRAY[0:9] |
10 |
ARRAY[1:3, 1:4] |
12 |
ARRAY[0:4, 0:4] |
25 |
Using elements
Marks[1] ← 62
Names[3] ← "Aisha"
Board[2, 3] ← 'X'
OUTPUT Marks[Position + 1]
- One index value per dimension.
- The index can be a number, a variable or an expression.
- An index outside the bounds is an error.
Loop patterns for 1D arrays
Input into an array
FOR Index ← 1 TO 10
INPUT Marks[Index]
NEXT Index
Total and average
Total ← 0
FOR Index ← 1 TO 10
Total ← Total + Marks[Index]
NEXT Index
OUTPUT Total / 10
Highest value
Highest ← Marks[1]
FOR Index ← 2 TO 10
IF Marks[Index] > Highest
THEN
Highest ← Marks[Index]
ENDIF
NEXT Index
Count items meeting a test
Count ← 0
FOR Index ← 1 TO 10
IF Marks[Index] >= 50
THEN
Count ← Count + 1
ENDIF
NEXT Index
Reverse order
FOR Index ← 10 TO 1 STEP -1
OUTPUT Marks[Index]
NEXT Index
Loop patterns for 2D arrays
Outer loop = rows, inner loop = columns. The inner loop completes for every pass of the outer loop.
Visit every element
FOR Row ← 1 TO 3
FOR Column ← 1 TO 4
OUTPUT Sales[Row, Column]
NEXT Column
NEXT Row
This runs the body 3 × 4 = 12 times.
Row totals
FOR Row ← 1 TO 3
RowTotal ← 0
FOR Column ← 1 TO 4
RowTotal ← RowTotal + Sales[Row, Column]
NEXT Column
OUTPUT RowTotal
NEXT Row
Column totals
Swap the loops: outer = column, inner = row, and reset the total inside the outer loop.
Setting all elements
FOR Row ← 1 TO 3
FOR Column ← 1 TO 3
Board[Row, Column] ← ' '
NEXT Column
NEXT Row
Worked trace
Array Data[1:4] holds 6, 2, 9, 4.
Result ← 0
FOR Index ← 1 TO 4
IF Data[Index] > 3
THEN
Result ← Result + Data[Index]
ENDIF
NEXT Index
OUTPUT Result
| Index | Data[Index] | Condition | Result |
|---|---|---|---|
| 1 | 6 | true | 6 |
| 2 | 2 | false | 6 |
| 3 | 9 | true | 15 |
| 4 | 4 | true | 19 |
The output is 19.
Why use an array
- One name for a whole list, so the program has fewer variables.
- A loop can process every element with the same code.
- The program is shorter and easier to change.
- The index can be calculated, so any element can be reached.
Answer templates
Why an array is better than separate variables (2 marks): one identifier stores many values of the same type; loops can be used to process them, so less code is needed.
Write pseudocode for an array task (5 marks): declare the array [1]; initialise any total, count or highest [1]; loop with the right bounds [1]; the array element with the loop variable as the index [1]; correct test or calculation and output after the loop [1].
Trace nested loops (3 marks): show the order of Row and Column; show the value used each time; give the final output.
Exam traps
- Wrong bounds.
ARRAY[1:10]has 10 elements, so the loop is 1 to 10. - No index.
Marksalone is not an element. - Swapped row and column.
Sales[Row, Column], in that order. - Total not reset. Reset row totals inside the outer loop.
- Highest initialised to 0. Start with the first element.
- Mixing data types. All elements in an array have the same type.
Self-test
- What is an array?
- Declare an array called Prices that holds 12 real numbers, with indexes 1 to 12.
- How many elements are in
ARRAY[1:5, 1:5]? - What does
Grid[2, 4]refer to? - Write a loop header that visits every element of
ARRAY[1:20]. - Why is a FOR loop used with an array?
- What is the output of
OUTPUT Data[2]if Data holds 6, 2, 9, 4? - Why must the total be set to 0 before the loop?
- In nested loops, which loop completes first?
- What is wrong with
FOR Index ← 1 TO 11forARRAY[1:10]? - How many times does the inner body run for
FOR Row ← 1 TO 4containingFOR Column ← 1 TO 6? - Why use a variable as an index?
Answers
- A fixed-length structure that holds several values of the same data type under one name.
DECLARE Prices : ARRAY[1:12] OF REAL-
- The element in row 2, column 4.
FOR Index ← 1 TO 20- The number of elements is known, and the loop variable can be the index.
-
- Otherwise the first addition starts from an unknown value and the total is wrong.
- The inner loop.
- Index 11 is outside the bounds of the array, which causes an error.
- 24 times (4 × 6).
- So that a loop (or a calculation) can choose which element to use, instead of writing a separate statement for each.
Related resources
-
Study guides
Cambridge O Level Computer Science (2210): File handling
Study guide to Cambridge O Level Computer Science 2210 section 8.3: why programs store data in files, and how to open, read, write and close a file using Cambridge pseudocode.
Computer Science · Cambridge · O Level
Read guide -
Practice questions
Cambridge O Level Computer Science (2210): File handling – Practice Questions
Original questions with answers on Cambridge O Level Computer Science 2210 section 8.3: why files are used, and opening, reading, writing and closing files in pseudocode.
Computer Science · Cambridge · O Level
Try questions -
Revision notes
Cambridge O Level Computer Science (2210): File handling – Revision Notes
Revision notes for Cambridge O Level Computer Science 2210 section 8.3: why files are used and the OPENFILE, READFILE, WRITEFILE and CLOSEFILE commands, with patterns and a self-test.
Computer Science · Cambridge · O Level
Revise topic
Get free revision emails (optional)
Occasional emails with practice questions, worked explanations and links to free resources for the qualification and subjects you choose. No spam, and you can unsubscribe from any email. The free tools on this site never need an email.