An array is a data structure that stores multiple values of the same data type under a single identifier. Each item is accessed using an index number, starting from 0 in AQA pseudocode.
scores = [85, 72, 91, 64, 78]
85
0
72
1
91
2
64
3
78
4
scores[0] = 85 · scores[2] = 91 · scores[4] = 78
AQA Array Syntax
Declaring and Using Arrays
DECLARING
scores ← [85, 72, 91, 64, 78]
names ← ['Ali', 'Ben', 'Cara']
READING & WRITING
OUTPUT scores[0]
scores[2] ← 95
name ← names[1]
← scores[0] outputs 85 ← scores[2] is now 95 ← name is now 'Ben'
Traversing Arrays
Looping Through an Array
PRINT ALL ITEMS
scores ← [85,72,91,64,78] FOR i ← 0 TO 4 OUTPUT scores[i] ENDFOR
FIND THE TOTAL
total ← 0 FOR i ← 0 TO 4 total ← total + scores[i] ENDFOR OUTPUT total
⚡ Tip:Use LEN(array) - 1 as the upper bound to avoid hard-coding array size.
Exam Practice
Have a go at this question
AQA-style question
An array called temps stores temperature readings: [12, 18, 9, 22, 15]. Write pseudocode to find and output the largest value in the array.
4 marks
temps ← [12,18,9,22,15] largest ← temps[0] FOR i ← 1 TO 4 IF temps[i] > largest THEN largest ← temps[i] ENDIF ENDFOR OUTPUT largest
Key Takeaways
What to Remember
Arrays store multiple values of the same type under one name