Cambridge pseudocode

9618 Pseudocode Guide

IGCSE pseudocode already has variables, loops, arrays and procedures. 9618 adds ways to group data and to share it. The sharp edge is which assignments copy and which ones alias.

How it works

A record is copied. An object is shared.

B <- A on a record duplicates the fields. Changing B.Score leaves A.Score at 1. The two variables are not the same record.

TYPE StudentRecord
    DECLARE Score : INTEGER
ENDTYPE

DECLARE A : StudentRecord
DECLARE B : StudentRecord
A.Score <- 1
B <- A
B.Score <- 9
OUTPUT A.Score
Output
1

B <- A on a class object copies the reference, not the object. B.Set writes the object A still points at, so A.Get() is 9. Two variables, one counter.

CLASS Counter
    PRIVATE Value : INTEGER
    PUBLIC PROCEDURE NEW(Start : INTEGER)
        Value <- Start
    ENDPROCEDURE
    PUBLIC PROCEDURE Set(N : INTEGER)
        Value <- N
    ENDPROCEDURE
    PUBLIC FUNCTION Get() RETURNS INTEGER
        RETURN Value
    ENDFUNCTION
ENDCLASS

DECLARE A : Counter
DECLARE B : Counter
A <- NEW Counter(1)
B <- A
CALL B.Set(9)
OUTPUT A.Get()
Output
9

That split is the rest of the A Level guide in miniature. BYREF is the procedure version of the shared object: the parameter is the caller’s variable. DATE values compare as dates, not as text. A CASE range such as 80 TO 100 is one label covering every integer in it. The full syntax, including pointers, sets and random-access files, stays in the Cambridge pseudocode guide. Practise in order on the 9618 path.

In Python

Assignment shares, unless you copy

Python objects behave like the class, not like the record. b = a makes a second name for the same dict. b = a.copy() is the record assignment.

Python
a = {"score": 1}
b = a
b["score"] = 9
print(a["score"])  # 9

a = {"score": 1}
b = a.copy()
b["score"] = 9
print(a["score"])  # 1

Beyond the exam

Value types and reference types

Languages pick a default and then give you an escape hatch. Cambridge copies records and shares objects. Python shares almost everything and makes you ask for a copy. C copies structs and makes you ask for a pointer. The exam wants you to know which Cambridge assignment is which. The useful habit is to ask, before you write B <- A, whether you wanted a snapshot or a second name.

Run the example in the pseudocode compiler online, or read the matching section of the Cambridge pseudocode guide. To practise in order, open the AS & A Level 9618 path.