SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
AQA 8525 · Section 3.2 · 3.2.2d

Arrays
(1D)

Declaring Arrays · Indexing · Traversal · Searching & Sorting

CSZoneAQA GCSE Computer Science 8525
What is an Array?

Storing Multiple Values

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
AQA uses index 0 for the first element: array[0]
Traverse with a FOR loop from 0 to LEN(array)-1
Declare with: name ← [val1, val2, val3]