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.
Arrays
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
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
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:
| Pseudocode | Python |
|---|---|
| SET x TO 5 | x = 5 |
| SEND x TO DISPLAY | print(x) |
| RECEIVE x FROM (INTEGER) KEYBOARD | x = int(input()) |
| LENGTH(word) | len(word) |
| a & b | a + b (for strings) |
| x MOD 2 | x % 2 |
| x DIV 2 | x // 2 |
| RANDOM(6) | random.randint(0, 6) |
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
- FOR EACH visits Ana, Ben and Cy.
- Ana and Ben have length 3; Cy has length 2.
- count becomes 2.
Answer: 2
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.
- 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 โ
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
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.
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.
- Pearson Edexcel International GCSE Computer Science (4CP0) specification
- Pearson Edexcel International GCSE Computer Science: pseudocode command set
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.