Arrays (SQA National 5 Computing Science): Revision Note
Exam code: X816 75
1-Dimensional Arrays
What is an array?
An array is an ordered collection of data items stored under one variable name
Each item in the array is called an element, and each element can be accessed using an index
An array can only store one data type (for example, all integers or all strings)
A 1-dimensional (1D) array stores data in a single list
Indexes start at 0 in most programming languages such as Python
In SQA pseudocode, arrays may start at 0 or 1, always follow the range given in the question

Concept comparison
Concept | SQA pseudocode | Python | Explanation |
|---|---|---|---|
Create |
|
| Creates a blank array with 5 elements (indexes 0–4) |
Assign values |
|
| Creates an array called scores with values assigned |
Change a value |
|
| Assigns the colour Red to index 4 (the 5th element) |
Example in pseudocode
Creating a one-dimensional array called
arraythat contains 5 integers
DECLARE array : ARRAY[0:4] OF INTEGER
SET array[0] TO 1
SET array[1] TO 2
SET array[2] TO 3
SET array[3] TO 4
SET array[4] TO 5
SEND array[0] TO DISPLAY // Output: 1
SEND array[2] TO DISPLAY // Output: 3
SET array[1] TO 10 // Modify element at index 1
SEND array TO DISPLAY // Displays [1, 10, 3, 4, 5]
FOR counter FROM 0 TO 4 DO
SEND array[counter] TO DISPLAY
END FOR
SET length TO 5
SEND length TO DISPLAY // Output: 5Example in Python
# Creating a one-dimensional array
array = [1, 2, 3, 4, 5]
# Accessing elements of the array
print(array[0]) # Output: 1
print(array[2]) # Output: 3
# Modifying elements of the array
array[1] = 10
print(array) # Output: [1, 10, 3, 4, 5]
# Iterating over the array
for element in array:
print(element)
# Output:
# 1
# 10
# 3
# 4
# 5
# Length of the array
length = len(array)
print(length) # Output: 5Worked Example
A teacher records the test scores of 5 pupils in a class.
The data is stored in a 1D array called testScores.
Index | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
Value | 45 | 67 | 89 | 73 | 56 |
(a) Write pseudocode to output the score stored at index 2.
[1]
(b) Write pseudocode to change the value stored at index 4 to 60.
[1]
(c) Write pseudocode to output all scores in the array using a loop.
[2]
Answers
(a) SEND testScores[2] TO DISPLAY [1 mark]
(b) SET testScores[4] TO 60 [1 mark]
(c)
FOR counter FROM 0 TO 4 DO
SEND testScores[counter] TO DISPLAY
END FOR[2 marks]
Unlock more, it's free!
Was this revision note helpful?