Pearson pseudocode: arrays, subprograms and files

Longer pseudocode algorithms use arrays, procedures and functions. Here is how Pearson writes them, with the Python you would use instead.

Practise this lesson free (7 questions)

Arrays

Arrays are indexed from 0. SET scores TO [12, 7, 19, 4] creates one; scores[2] is 19. LENGTH(scores) gives the number of items (LENGTH also works on strings).
A two-dimensional array is indexed [row, column]. If grid holds the rows [3, 8, 1] and [6, 2, 9], then grid[1, 2] is 9. (Python writes grid[1][2].)
SET scores TO [12, 7, 19, 4]
SET total TO 0
FOR index FROM 0 TO LENGTH(scores) - 1 DO
SET total TO total + scores[index]
END FOR
SEND total TO DISPLAY
This outputs 42: the loop runs from index 0 to LENGTH - 1.

Procedures and functions

A procedure carries out a task and does not return a value:
PROCEDURE showLine (symbol, size)
BEGIN PROCEDURE
SET line TO ''
REPEAT size TIMES
SET line TO line & symbol
END REPEAT
SEND line TO DISPLAY
END PROCEDURE

showLine ('-', 5)
Output: -----
A function returns a value with RETURN:
FUNCTION area (width, height)
BEGIN FUNCTION
SET result TO width * height
RETURN result
END FUNCTION

SEND area (4, 6) TO DISPLAY
Output: 24
The values in brackets are parameters. A subprogram is called by its name followed by the values to pass in.

Other commands

FOR EACH name FROM names DO ... END FOREACH visits every item of an array.
RANDOM(n) gives a random whole number from 0 to n.
READ file record and WRITE file record read and write records in a file.
In the exam you can answer in any clear pseudocode or in Python, so translate as you read:
PseudocodePython
SET x TO 5x = 5
SEND x TO DISPLAYprint(x)
RECEIVE x FROM (INTEGER) KEYBOARDx = int(input())
LENGTH(word)len(word)
a & ba + b (for strings)
x MOD 2x % 2
x DIV 2x // 2
RANDOM(6)random.randint(0, 6)
Worked example

What is output?
SET names TO ['Ana', 'Ben', 'Cy']
SET count TO 0
FOR EACH name FROM names DO
IF LENGTH(name) = 3 THEN
SET count TO count + 1
END IF
END FOREACH
SEND count TO DISPLAY

  1. FOR EACH visits Ana, Ben and Cy.
  2. Ana and Ben have length 3; Cy has length 2.
  3. count becomes 2.

Answer: 2

Key idea

Pseudocode arrays start at index 0, use LENGTH() and [row, column] for 2D arrays. PROCEDURE ... END PROCEDURE does a task; FUNCTION ... RETURN ... END FUNCTION returns a value. FOR EACH visits every item.

Key words
PROCEDURE ... END PROCEDURE
A subprogram that does not return a value. Python: def name(parameters):
Procedure
A subprogram that carries out a task but does not return a value.
FUNCTION ... RETURN ... END FUNCTION
A subprogram that returns a value. Python: def with return
Function
A subprogram that returns a value.
Array
A data structure holding many items of the same type under one name, accessed by index (a list in Python).
SET total TO 0
Assignment. Python: total = 0

All GCSE and International GCSE Computer Science key terms and definitions โ†’

Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. SET scores TO [9, 14, 6, 21]. What is scores[2]?

    Show the answer

    Answer: 6

    Arrays start at index 0: scores[0] = 9, scores[1] = 14, scores[2] = 6.

  2. A 2D array grid holds two rows: [3, 8, 1] and [6, 2, 9]. What is grid[1, 2]?

    Show the answer

    Answer: 9

    Row 1 is [6, 2, 9]; column 2 is 9.

Check you have got it

Answer 7 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Checked by the GCSE-ready editorial team, 17 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

Related lessons