CAIE A-Level Pseudocode Reference Cambridge 9618 / 9608

CAIE Pseudocode
How-To Guide

A complete reference for writing Cambridge A-Level pseudocode — from first principles to object-oriented programming. Use the sidebar to jump to any topic.

9618 Computer Science 9608 Computer Science A-Level & AS-Level Full Syllabus Coverage
🏠

Introduction

Pseudocode is a plain-language description of an algorithm. CAIE (Cambridge Assessment International Education) defines a specific pseudocode style used in A-Level Computer Science exams (syllabus codes 9618 and 9608). It is not a real programming language — it cannot be directly compiled — but it follows strict conventions so that any examiner can read and mark it consistently.

Key things to know before you start:

Case Sensitivity
Keywords are written in UPPERCASE. Identifiers (variable names) use a consistent casing — typically camelCase or PascalCase.
Indentation
Indent code inside blocks (IF, FOR, WHILE, etc.) by three or four spaces for clarity. Consistent indentation is required.
Comments
Anything after // on a line is a comment and is ignored logically. Use them to explain your code.
No Semicolons
Statements end at the end of the line — no semicolons or other terminators are needed.
PSEUDOCODE
Hello World example
// A simple first program
DECLARE Name : STRING
OUTPUT "What is your name? "
INPUT Name
OUTPUT "Hello, " & Name & "!"
🔷

Data Types

Every value in CAIE pseudocode has a data type. You must declare the type of every variable before using it.

Type Description Example Values
INTEGERWhole numbers (positive, negative, or zero)0, 42, -7
REALNumbers with a decimal point3.14, -0.5, 2.0
CHARA single character (enclosed in single quotes)'A', '9', ' '
STRINGA sequence of zero or more characters (enclosed in double quotes)"Hello", "42", ""
BOOLEANA logical value — either TRUE or FALSETRUE, FALSE
DATEStores a calendar date17/04/2026
💡 Tip Note the difference between CHAR (single quotes, one character) and STRING (double quotes, any length). Mixing them up is a common exam mistake.

Enumerated Types

You can define your own type with a fixed set of named values:

PSEUDOCODE
TYPE Season = (Spring, Summer, Autumn, Winter)
DECLARE CurrentSeason : Season
CurrentSeason <- Summer

Pointer Types

Pointer types store the memory address of another variable:

PSEUDOCODE
TYPE IntPointer = ^INTEGER
DECLARE Ptr : IntPointer
📦

Variables & Constants

All variables must be declared before they are used. Constants are declared with a fixed value that cannot change during program execution.

Declaring Variables

PSEUDOCODE
DECLARE Age : INTEGER
DECLARE Price : REAL
DECLARE Initial : CHAR
DECLARE FullName : STRING
DECLARE IsValid : BOOLEAN

Declaring Constants

PSEUDOCODE
CONSTANT PI <- 3.14159
CONSTANT MAX_SIZE <- 100
CONSTANT GREETING <- "Hello"
⚠️ Important Constants are assigned with <- at declaration time and must never be reassigned later in the program.
💬

Input / Output

Use INPUT to read a value from the user and OUTPUT (or PRINT) to display a value.

PSEUDOCODE
DECLARE Score : INTEGER
DECLARE PlayerName : STRING

OUTPUT "Enter your name: "
INPUT PlayerName

OUTPUT "Enter your score: "
INPUT Score

OUTPUT PlayerName & " scored: " & Score

The & operator concatenates (joins) strings and values together in an OUTPUT statement.

✅ Tip Both OUTPUT and PRINT are accepted in CAIE exams. OUTPUT is the preferred, official keyword.

Operators

Arithmetic Operators

OperatorMeaningExampleResult
+Addition7 + 310
-Subtraction7 - 34
*Multiplication7 * 321
/Division (real result)7 / 23.5
DIVInteger division (floor)7 DIV 23
MODRemainder after integer division7 MOD 21
^Exponentiation (power)2 ^ 8256

Comparison Operators

These return TRUE or FALSE and are used in conditions:

OperatorMeaning
=Equal to
<>Not equal to
<Less than
>Greater than
<=Less than or equal to
>=Greater than or equal to

Logical (Boolean) Operators

OperatorMeaningExample
ANDBoth conditions must be TRUEAge >= 18 AND HasID = TRUE
ORAt least one condition must be TRUEScore > 90 OR Award = TRUE
NOTInverts the Boolean valueNOT IsFinished

String Concatenation

PSEUDOCODE
DECLARE FullName : STRING
FullName <- "Alice" & " " & "Smith"   // "Alice Smith"
🔁

Assignment

The assignment operator <- stores a value into a variable. The variable must already have been declared with a matching type.

PSEUDOCODE
DECLARE Counter : INTEGER
DECLARE Total   : REAL
DECLARE Message : STRING

Counter <- 0
Total   <- 0.0
Message <- "Starting..."

// Increment a counter
Counter <- Counter + 1

// Compute a value
Total <- Counter * 3.5
Note CAIE uses <- for assignment, not =. The equals sign (=) is only used for comparison.
🔀

Selection — IF and CASE

Selection allows the program to choose different paths based on a condition.

IF … THEN … ENDIF

PSEUDOCODE
IF Score >= 50
  THEN
    OUTPUT "Pass"
ENDIF

IF … THEN … ELSE … ENDIF

PSEUDOCODE
IF Score >= 50
  THEN
    OUTPUT "Pass"
  ELSE
    OUTPUT "Fail"
ENDIF

Nested IF (ELSE IF)

PSEUDOCODE
IF Score >= 90
  THEN
    OUTPUT "Grade A"
  ELSE
    IF Score >= 70
      THEN
        OUTPUT "Grade B"
      ELSE
        IF Score >= 50
          THEN
            OUTPUT "Grade C"
          ELSE
            OUTPUT "Fail"
        ENDIF
    ENDIF
ENDIF

CASE OF … ENDCASE

Use CASE OF when selecting from several possible values of a single variable (similar to switch/match in other languages):

PSEUDOCODE
DECLARE Day : INTEGER
INPUT Day

CASE OF Day
  1 : OUTPUT "Monday"
  2 : OUTPUT "Tuesday"
  3 : OUTPUT "Wednesday"
  4 : OUTPUT "Thursday"
  5 : OUTPUT "Friday"
  6, 7 : OUTPUT "Weekend"
  OTHERWISE : OUTPUT "Invalid day"
ENDCASE
Note The OTHERWISE clause in CASE OF is the default — it runs when no other value matches. It is equivalent to ELSE in an IF statement.
🔄

Iteration — Loops

CAIE pseudocode has three loop structures. Choose the right one based on whether the repetition count is known in advance.

FOR … TO … NEXT (Count-Controlled)

Use when the number of iterations is known before the loop starts:

PSEUDOCODE
// Print 1 to 10
FOR i <- 1 TO 10
  OUTPUT i
NEXT i

// Count down from 10 to 1 using STEP
FOR i <- 10 TO 1 STEP -1
  OUTPUT i
NEXT i

WHILE … DO … ENDWHILE (Pre-condition)

The condition is checked before each iteration. If it is FALSE from the start, the loop body never executes:

PSEUDOCODE
DECLARE Number : INTEGER
INPUT Number

WHILE Number <> 0 DO
  OUTPUT "Number is: " & Number
  INPUT Number
ENDWHILE

REPEAT … UNTIL (Post-condition)

The body runs at least once; the condition is checked after each iteration. The loop stops when the condition becomes TRUE:

PSEUDOCODE
DECLARE Password : STRING

REPEAT
  OUTPUT "Enter password: "
  INPUT Password
UNTIL Password = "secret123"
Choosing the right loop
  • Known number of iterations → FOR … NEXT
  • Unknown, check first → WHILE … ENDWHILE
  • Unknown, run at least once → REPEAT … UNTIL
🗂️

Arrays

An array is a fixed-size collection of elements of the same data type. CAIE arrays are 1-indexed by default (the first element is at index 1), but any lower bound can be used.

Declaring a 1D Array

PSEUDOCODE
// ARRAY [lower:upper] OF type
DECLARE Scores : ARRAY[1:10] OF INTEGER
DECLARE Names  : ARRAY[1:5]  OF STRING

// Assign values
Scores[1] <- 85
Scores[2] <- 72

// Read values
OUTPUT Scores[1]    // outputs 85

Iterating Through an Array

PSEUDOCODE
DECLARE Scores : ARRAY[1:5] OF INTEGER
DECLARE i      : INTEGER
DECLARE Total  : INTEGER

Total <- 0

FOR i <- 1 TO 5
  INPUT Scores[i]
  Total <- Total + Scores[i]
NEXT i

OUTPUT "Average: " & Total / 5

Declaring a 2D Array

PSEUDOCODE
// A 3-row × 4-column grid of integers
DECLARE Grid : ARRAY[1:3, 1:4] OF INTEGER
DECLARE Row, Col : INTEGER

// Fill grid with zeros
FOR Row <- 1 TO 3
  FOR Col <- 1 TO 4
    Grid[Row, Col] <- 0
  NEXT Col
NEXT Row
🗃️

Records (Composite / User-Defined Types)

A record (also called a composite type or struct) groups together fields of different types under a single name. Useful for storing related data — e.g. all details about a student.

Defining and Using a Record Type

PSEUDOCODE
// Define the type
TYPE Student
  DECLARE Name   : STRING
  DECLARE Age    : INTEGER
  DECLARE Grade  : CHAR
ENDTYPE

// Declare a variable of that type
DECLARE Pupil1 : Student

// Assign field values using dot notation
Pupil1.Name  <- "Alice"
Pupil1.Age   <- 17
Pupil1.Grade <- 'A'

// Output a field
OUTPUT Pupil1.Name & " is in grade " & Pupil1.Grade

Array of Records

PSEUDOCODE
DECLARE ClassList : ARRAY[1:30] OF Student
ClassList[1].Name <- "Bob"
ClassList[1].Age  <- 16
🔧

Procedures

A procedure is a named block of code that performs a task. It does not return a value. Call it by name.

Defining a Procedure

PSEUDOCODE
PROCEDURE Greet(Name : STRING)
  OUTPUT "Hello, " & Name & "!"
ENDPROCEDURE

Calling a Procedure

PSEUDOCODE
CALL Greet("Alice")    // outputs: Hello, Alice!
CALL Greet("Bob")      // outputs: Hello, Bob!

Procedure with No Parameters

PSEUDOCODE
PROCEDURE PrintDivider()
  OUTPUT "----------------------------"
ENDPROCEDURE

CALL PrintDivider()
⚙️

Functions

A function is like a procedure but it returns a value. Declare its return type with RETURNS and use RETURN inside to send the value back.

Defining a Function

PSEUDOCODE
FUNCTION Square(n : INTEGER) RETURNS INTEGER
  RETURN n * n
ENDFUNCTION

Calling a Function

PSEUDOCODE
DECLARE Result : INTEGER
Result <- Square(5)      // Result = 25
OUTPUT Square(7)          // outputs 49

A More Complex Function

PSEUDOCODE
FUNCTION IsEven(n : INTEGER) RETURNS BOOLEAN
  IF n MOD 2 = 0
    THEN
      RETURN TRUE
    ELSE
      RETURN FALSE
  ENDIF
ENDFUNCTION
📋

Parameters — BYVALUE and BYREF

Parameters can be passed to procedures and functions in two ways:

ModeKeywordBehaviour
By Value BYVALUE A copy of the argument is passed. Changes inside the subprogram do not affect the original variable. (Default if not specified.)
By Reference BYREF The actual variable is passed. Changes inside the subprogram do affect the original variable.
PSEUDOCODE
// BYVALUE — original is not changed
PROCEDURE DoubleIt(BYVALUE x : INTEGER)
  x <- x * 2
  OUTPUT x
ENDPROCEDURE

// BYREF — original IS changed
PROCEDURE AddTen(BYREF value : INTEGER)
  value <- value + 10
ENDPROCEDURE

DECLARE Num : INTEGER
Num <- 5
CALL AddTen(Num)
OUTPUT Num   // outputs 15
✅ Tip Use BYREF when a procedure needs to modify the caller's variable (e.g. a sorting procedure). Use BYVALUE (or omit it) when you only need to read the argument.
📁

File Handling

CAIE pseudocode supports reading from and writing to text files using a small set of keywords.

KeywordPurpose
OPENFILEOpens a file for reading or writing
READFILEReads the next line from an open file into a variable
WRITEFILEWrites a value/string to an open file
CLOSEFILECloses a file (always do this when finished)
EOF()Returns TRUE when the end of file has been reached

File Modes

ModeMeaning
READOpen for reading only
WRITEOpen for writing (creates file or overwrites)
APPENDOpen for appending (adds to end of existing file)

Reading from a File

PSEUDOCODE
DECLARE Line : STRING

OPENFILE "data.txt" FOR READ
WHILE NOT EOF("data.txt") DO
  READFILE "data.txt", Line
  OUTPUT Line
ENDWHILE
CLOSEFILE "data.txt"

Writing to a File

PSEUDOCODE
OPENFILE "output.txt" FOR WRITE
WRITEFILE "output.txt", "Hello, world!"
WRITEFILE "output.txt", "Second line"
CLOSEFILE "output.txt"

Appending to a File

PSEUDOCODE
OPENFILE "log.txt" FOR APPEND
WRITEFILE "log.txt", "New log entry"
CLOSEFILE "log.txt"
🏗️

Object-Oriented Programming (OOP)

CAIE A-Level pseudocode supports full object-oriented programming, including classes, inheritance, and polymorphism.

Defining a Class

PSEUDOCODE
CLASS Animal
  PRIVATE Name  : STRING
  PRIVATE Sound : STRING

  PUBLIC PROCEDURE NEW(n : STRING, s : STRING)
    Name  <- n
    Sound <- s
  ENDPROCEDURE

  PUBLIC PROCEDURE Speak()
    OUTPUT Name & " says " & Sound
  ENDPROCEDURE

  PUBLIC FUNCTION GetName() RETURNS STRING
    RETURN Name
  ENDFUNCTION
ENDCLASS

Creating and Using Objects

PSEUDOCODE
DECLARE MyDog : Animal
MyDog <- NEW Animal("Rex", "Woof")
CALL MyDog.Speak()          // Rex says Woof
OUTPUT MyDog.GetName()      // Rex

Inheritance

Use INHERITS to create a subclass. The subclass gains all the public methods and attributes of the parent:

PSEUDOCODE
CLASS Dog INHERITS Animal
  PRIVATE Breed : STRING

  PUBLIC PROCEDURE NEW(n : STRING, b : STRING)
    CALL SUPER.NEW(n, "Woof")   // call parent constructor
    Breed <- b
  ENDPROCEDURE

  PUBLIC FUNCTION GetBreed() RETURNS STRING
    RETURN Breed
  ENDFUNCTION
ENDCLASS

DECLARE Fido : Dog
Fido <- NEW Dog("Fido", "Labrador")
CALL Fido.Speak()           // Fido says Woof  (inherited)
OUTPUT Fido.GetBreed()     // Labrador
Access Modifiers
  • PUBLIC — accessible from outside the class
  • PRIVATE — accessible only within the class (encapsulation)
📚

Built-in Functions

CAIE pseudocode provides a set of standard library functions you can use without defining them yourself.

String Functions

FunctionDescriptionExample
LEFT(s, n)First n characters of string sLEFT("Hello", 3)"Hel"
RIGHT(s, n)Last n characters of string sRIGHT("Hello", 3)"llo"
MID(s, start, n)n characters from position startMID("Hello", 2, 3)"ell"
LENGTH(s)Number of characters in string sLENGTH("Hi")2
LCASE(s)Converts string to lowercaseLCASE("Hello")"hello"
UCASE(s)Converts string to uppercaseUCASE("hello")"HELLO"
TO_UPPER(c)Converts a CHAR to uppercaseTO_UPPER('a')'A'
TO_LOWER(c)Converts a CHAR to lowercaseTO_LOWER('A')'a'

Numeric Functions

FunctionDescriptionExample
INT(x)Converts a REAL to INTEGER (truncates)INT(3.9)3
ROUND(x, n)Rounds x to n decimal placesROUND(3.567, 2)3.57
RAND(n)Returns a random REAL in range 0 ≤ r < nRAND(10) → e.g. 7.3

Type Conversion

FunctionDescriptionExample
NUM_TO_STR(n)Converts a number to a STRINGNUM_TO_STR(42)"42"
STR_TO_NUM(s)Converts a STRING to a numberSTR_TO_NUM("42")42
ASC(c)ASCII code of a characterASC('A')65
CHR(n)Character from ASCII codeCHR(65)'A'
IS_NUM(s)Returns TRUE if string is a valid numberIS_NUM("42")TRUE
📝

Style Conventions & Exam Tips

Follow these conventions to write clear, mark-worthy pseudocode in exams.

UPPERCASE Keywords
All reserved words — IF, WHILE, DECLARE, etc. — must be fully capitalised.
Consistent Naming
Use descriptive names like StudentScore, not x. PascalCase for variables and procedures is standard.
Indentation
Indent the body of every block (IF, FOR, WHILE, etc.) consistently — 3 or 4 spaces works well.
Declare Everything
Always DECLARE variables with their type before use — marks may be lost otherwise.
Use Comments
Add // comments to explain complex logic. Examiners appreciate clarity.
Match Brackets
Every IF needs ENDIF, every FOR needs NEXT, every WHILE needs ENDWHILE, etc.

Common Mistakes to Avoid

⚠️ Pitfalls
  • Using = for assignment instead of <-
  • Forgetting to close blocks (ENDIF, ENDWHILE, ENDFUNCTION)
  • Confusing CHAR (single quotes) with STRING (double quotes)
  • Using 0-based array indexing — CAIE arrays start at index 1 by default
  • Forgetting CALL when invoking a procedure
  • Using RETURN in a PROCEDURE — only FUNCTIONs return values
  • Not closing files after use with CLOSEFILE

Quick Syntax Reference

PSEUDOCODE Full template
// ── Declarations ──────────────────────────────────────
DECLARE MyVar  : INTEGER
CONSTANT MAX  <- 100

// ── Assignment ─────────────────────────────────────────
MyVar <- 42

// ── Input / Output ─────────────────────────────────────
INPUT MyVar
OUTPUT "Value is: " & MyVar

// ── Selection ──────────────────────────────────────────
IF MyVar > 0 THEN
    OUTPUT "Positive"
ELSE
    OUTPUT "Non-positive"
ENDIF

// ── Loops ──────────────────────────────────────────────
FOR i <- 1 TO MAX
    OUTPUT i
NEXT i

WHILE MyVar <> 0 DO
    INPUT MyVar
ENDWHILE

REPEAT
    INPUT MyVar
UNTIL MyVar = 0

// ── Subprograms ────────────────────────────────────────
PROCEDURE DoSomething(BYREF x : INTEGER)
    x <- x + 1
ENDPROCEDURE

FUNCTION GetDouble(x : INTEGER) RETURNS INTEGER
    RETURN x * 2
ENDFUNCTION