Pro Content

Upgrade to access all Cambridge 9618 lessons including pseudocode, trace tables, and programming content.

Upgrade to Pro →
← Back to Dashboard
🧩 Paper 2 · 2.1 Algorithm Design
2.1.2 Pseudocode and Trace Tables
Cambridge 9618 · International A Level Computer Science · ~14 min read
Notes
Video
Slides
Quiz
Worksheet

Cambridge 9618 Pseudocode Reference

Cambridge 9618 has a very specific pseudocode syntax that must be used in Paper 2. Deviation from these conventions will lose marks. The complete syntax is covered below.

Variables and Assignment

Declaring Variables

DECLARE x : INTEGER
DECLARE name : STRING
DECLARE score : REAL
DECLARE flag : BOOLEAN
DECLARE ch : CHAR

Assignment

x ← 10
name ← "Alice"
score ← 98.5
flag ← TRUE
ch ← 'A'

Input and Output

Input

INPUT x
INPUT name

Output

OUTPUT x
OUTPUT "Hello ", name
OUTPUT "Score: ", score

Selection — IF and CASE

IF score >= 80
  THEN OUTPUT "Distinction"
  ELSE OUTPUT "Pass"
ENDIF

// CASE statement
CASE grade OF
  'A' : OUTPUT "Excellent"
  'B' : OUTPUT "Good"
  OTHERWISE OUTPUT "Try harder"
ENDCASE

Iteration — FOR, WHILE, REPEAT-UNTIL

// FOR loop (count-controlled)
FOR i ← 1 TO 10
  OUTPUT i
NEXT i

// WHILE loop (condition checked before body)
WHILE count < 10 DO
  count ← count + 1
ENDWHILE

// REPEAT-UNTIL (condition checked after body)
REPEAT
  INPUT num
UNTIL num > 0

Procedures and Functions

PROCEDURE Greet(name : STRING)
  OUTPUT "Hello, ", name
ENDPROCEDURE

CALL Greet("Alice")

// Function — MUST use RETURNS keyword
FUNCTION Square(n : INTEGER) RETURNS INTEGER
  RETURN n * n
ENDFUNCTION

result ← Square(5)

Trace Tables

A trace table is a manual simulation of algorithm execution. You create a column for each variable and track how values change line-by-line. Cambridge exam questions ask you to complete trace tables — marks are lost for missing rows or wrong variable values.

Key rules for trace tables:

  • Create a column for every variable that changes
  • Also add a column for any OUTPUT values
  • Show the value of a variable only when it changes (leave blank otherwise)
  • Show each iteration of a loop as a separate row
  • If an array is involved, track the specific element (e.g., A[2])

Worked Example — Trace this algorithm:

DECLARE x : INTEGER
DECLARE y : INTEGER
x ← 1
y ← 0
WHILE x <= 4 DO
  y ← y + x
  x ← x + 1
ENDWHILE
OUTPUT y

Completed trace table:

xyx <= 4?OUTPUT
10
TRUE
1
2
TRUE
3
3
TRUE
6
4
TRUE
10
5
FALSE
10

The algorithm sums 1+2+3+4 = 10. The trace shows y accumulating the sum, and x incrementing until x=5 makes the WHILE condition false.

Complete Pseudocode Quick Reference

ConstructCambridge 9618 SyntaxNotes
Assignmentx ← 5Use ← not = or :=
Comparisonx = 5= used for equals comparison in conditions
Not equalx <> 5Not != or ≠
AND/OR/NOTAND OR NOTAlways uppercase keywords
String concatstr1 & str2Ampersand for concatenation
Integer dividex DIV yTruncates to integer
Modulox MOD yRemainder after division
For loopFOR i ← 1 TO 10 ... NEXT iNEXT not ENDFOR
For with stepFOR i ← 10 TO 1 STEP -2STEP can be negative
While loopWHILE cond DO ... ENDWHILECondition checked before body
Repeat loopREPEAT ... UNTIL condCondition checked after body (runs at least once)
IF statementIF cond THEN ... ELSE ... ENDIFELSE is optional
CASE statementCASE var OF 'A': ... ENDCASEOTHERWISE for default
ArrayDECLARE A : ARRAY[1:10] OF INTEGER1-indexed by default
2D arrayDECLARE M : ARRAY[1:3,1:3] OF REALRow, Column indexing
ProcedurePROCEDURE name(p:T) ... ENDPROCEDURECalled with CALL
FunctionFUNCTION f(p:T) RETURNS T ... ENDFUNCTIONMust have RETURNS keyword
Exam tip: Cambridge mark schemes are strict — using = instead of ← for assignment, or ENDFOR instead of NEXT i, will lose the mark for that line. Trace tables must show every row — if a variable's value doesn't change in a row, leave that cell blank (don't copy the previous value).
⚠️ Common Mistakes
  • Using = for assignment — always use
  • Writing ENDFOR — Cambridge uses NEXT i
  • Confusing WHILE (pre-check) with REPEAT-UNTIL (post-check) — REPEAT always executes body at least once
  • Functions vs procedures: functions use RETURNS type and RETURN value; procedures don't return a value
  • In trace tables: filling in unchanged values in every row — only fill when a variable changes
  • Forgetting to declare variables with DECLARE name : TYPE
✅ Notes completed!
Video coming soon
Click slide or press arrow keys to navigate

Worksheet — 2.1.2 Pseudocode and Trace Tables

6 questions · instantly marked · Cambridge 9618 standard

Q1Write Cambridge 9618 pseudocode to declare a variable total of type REAL, assign it the value 0, then add 3.5 to it three times using a WHILE loop.[5]
✅ Mark scheme
DECLARE total : REAL [1]; total ← 0 [1]; DECLARE count : INTEGER; count ← 0; WHILE count < 3 DO [1]; total ← total + 3.5 [1]; count ← count + 1; ENDWHILE [1].
Q2State the difference between a WHILE loop and a REPEAT-UNTIL loop in Cambridge 9618 pseudocode, with respect to when the condition is checked.[2]
✅ Mark scheme
WHILE loop: condition checked before the loop body executes — the body may never execute if the condition is initially false [1]; REPEAT-UNTIL: condition checked after the body executes — the body always executes at least once [1].
Q3Write a Cambridge 9618 FUNCTION called Cube that takes an integer parameter n and returns n³.[3]
✅ Mark scheme
FUNCTION Cube(n : INTEGER) RETURNS INTEGER [1]; RETURN n * n * n [1]; ENDFUNCTION [1]. (Deduct 1 if RETURNS keyword missing or ENDFUNCTION missing.)
Q4Complete the trace table for this algorithm with inputs 7, 3:
INPUT a
INPUT b
WHILE a > b DO
  a ← a - b
ENDWHILE
OUTPUT a
[4]
✅ Mark scheme
Initial: a=7, b=3 [1]; Check: 7>3=TRUE, a←7-3=4 [1]; Check: 4>3=TRUE, a←4-3=1 [1]; Check: 1>3=FALSE, EXIT loop; OUTPUT 1 [1]. (This computes 7 MOD 3 = 1.)
Q5In Cambridge 9618 pseudocode, what is the difference between using DIV and MOD? Give an example of each using the values 17 and 5.[4]
✅ Mark scheme
DIV gives the integer quotient (whole number result) of integer division [1]; 17 DIV 5 = 3 [1]; MOD gives the remainder after integer division [1]; 17 MOD 5 = 2 [1]. (17 = 5×3 + 2, so quotient is 3, remainder is 2.)
Q6Write a Cambridge 9618 pseudocode PROCEDURE called PrintSquares that takes a parameter n : INTEGER and outputs the square of each integer from 1 to n.[4]
✅ Mark scheme
PROCEDURE PrintSquares(n : INTEGER) [1]; FOR i ← 1 TO n [1]; OUTPUT i * i [1]; NEXT i [1]; ENDPROCEDURE. (Award 3 if ENDPROCEDURE missing.)
Q7Write pseudocode for a function CountVowels(Word : STRING) RETURNS INTEGER that counts and returns the number of vowels (A, E, I, O, U — case-insensitive) in the input string. Use a FOR loop and an appropriate string function.[5]
✅ Mark scheme
FUNCTION CountVowels(Word : STRING) RETURNS INTEGER [1]; DECLARE Count : INTEGER ← 0 and DECLARE Ch : CHAR [1]; FOR loop iterating from 1 to LENGTH(Word) [1]; Ch ← UCASE(MID(Word, i, 1)) or equivalent extraction of each character [1]; IF Ch = 'A' OR Ch = 'E' OR Ch = 'I' OR Ch = 'O' OR Ch = 'U' THEN Count ← Count + 1 [1]; NEXT i / ENDFOR; RETURN Count / ENDFUNCTION [1 bonus]. Award max 5.
Q8Explain the difference between a FUNCTION and a PROCEDURE in CAIE pseudocode. State one situation where a FUNCTION is more appropriate than a PROCEDURE, and one where a PROCEDURE is more appropriate. Give a one-line pseudocode declaration for each.[5]
✅ Mark scheme
FUNCTION returns a single value to the calling code; PROCEDURE performs an action but does not return a value [1]; FUNCTION appropriate: calculating and returning a result e.g. square root, total of array — the result is used directly in an expression [1]; example: FUNCTION Square(n : INTEGER) RETURNS INTEGER [1]; PROCEDURE appropriate: performing an output operation or modifying multiple variables via BYREF — no return value needed [1]; example: PROCEDURE PrintReport(Data : ARRAY) [1]. Award max 5.
Topic Quiz
Question 1 of 10
You scored
out of 10
Card 1 of 7
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — 2.1.2 Pseudocode

10 questions · 10 marks · 10 minutes

← 2.1.1 Problem Solving
35 of 82 · Cambridge 9618
2.1.3 Abstraction & Decomposition →