Score
0 / 89
Cambridge Assessment International Education AS & A Level 9618

Computer Science • Paper 2

Pseudocode Guide
for Students

Complete Study & Practice Book

A comprehensive guided learning resource covering all ten chapters of the Cambridge 9618 Pseudocode Guide. Each chapter provides theory, worked examples, and 89 practice questions with full explanations. Use for examinations in 2026.

Contents

Ten chapters covering the complete Cambridge 9618 Pseudocode Guide

Chapter 1 Pseudocode Conventions 8 questions
Chapter 2 Variables, Constants & Data Types 10 questions
Chapter 3 Arrays 8 questions
Chapter 4 User-Defined Data Types 9 questions
Chapter 5 Common Operations 10 questions
Chapter 6 Selection 8 questions
Chapter 7 Iteration (Repetition) 10 questions
Chapter 8 Procedures & Functions 9 questions
Chapter 9 File Handling 8 questions
Chapter 10 Object-Oriented Programming 9 questions
I

Chapter 1

Pseudocode Conventions

Theory & Syntax Reference

1.1 Font Style & Indentation

Pseudocode is presented in a monospaced font (Courier New). Lines inside a block are indented by three spaces — this makes structure instantly visible.

IF Score > 50 THEN
   OUTPUT "Pass"
ENDIF

1.2 Case Rules

Keywords are always UPPER CASE: IF, REPEAT, FOR, PROCEDURE.

Identifiers (variable names) use camelCase or PascalCase: numberOfPlayers, TotalScore.

Meta-variables (placeholders) are enclosed in angle brackets: <condition>.

REPEAT
   <statement(s)>
UNTIL <condition>

1.3 Comments

Comments begin with // and run to the end of the line. They are never executed — they exist only to explain the code.

// this procedure swaps values of X and Y
PROCEDURE SWAP(BYREF X : INTEGER, Y : INTEGER)
   Temp <- X   // temporarily store X
   X <- Y
   Y <- Temp
ENDPROCEDURE

1.4 Line Numbering

When an exam numbers pseudocode lines, numbers appear to the left. Continuation lines (when a statement wraps to the next line) are not numbered.

1  DECLARE Counter : INTEGER
2  Counter <- 0
3  WHILE Counter < 10
4     Counter <- Counter + 1
5  ENDWHILE
✎ Practice Questions
Chapter progress:
0 / 8

Which of the following correctly describes how keywords appear in Cambridge pseudocode?

Identifiers in Cambridge pseudocode should be written in:

How are comments written in Cambridge pseudocode?

What does a comment do in pseudocode?

Lines inside a block are indented by how many spaces?

Which is a valid identifier?

Continuation lines in numbered pseudocode are:

Meta-variables (placeholders) in pseudocode are enclosed in:

II

Chapter 2

Variables, Constants & Data Types

Theory & Syntax Reference

2.1 Data Types

Six primitive data types are used in Cambridge pseudocode:

KeywordMeaningExample literal
INTEGERWhole number42
REALNumber with fractional part3.14
CHARSingle character'A'
STRINGSequence of characters"Hello"
BOOLEANLogical valueTRUE
DATECalendar date01/04/2026

2.2 Literals

A literal is a value written directly in code. Key rules:

  • Real — must have a digit on both sides of the decimal: 0.3, 4.0
  • Char — single quotes: 'x'
  • String — double quotes: "text" or "" (empty)
  • BooleanTRUE or FALSE

2.3 Variable Declarations

Declare variables with DECLARE before using them. Syntax: DECLARE <name> : <type>

DECLARE Counter : INTEGER
DECLARE TotalPay : REAL
DECLARE GameOver : BOOLEAN
DECLARE Initial : CHAR
DECLARE PlayerName : STRING

2.4 Constants

Use CONSTANT for values that never change. Only literals allowed as values.

CONSTANT MaxPlayers = 4
CONSTANT Pi = 3.14159
CONSTANT DefaultText = "N/A"

2.5 Assignments

The assignment operator is (left-arrow). It stores a value in a variable.

Python note: Python uses = for assignment.

Counter <- 0
Counter <- Counter + 1
TotalPay <- NumberOfHours * HourlyRate
GameOver <- FALSE
✎ Practice Questions
Chapter progress:
0 / 10

Which data type stores 3.14?

Correct way to declare Score as integer:

Which is a valid REAL literal?

Purpose of the CONSTANT keyword:

Correct assignment statement:

Data type of TRUE:

Correct constant declaration:

Can you assign integer 17 to a REAL variable?

Are identifiers case-sensitive in Cambridge pseudocode?

Which is NOT a valid identifier?

III

Chapter 3

Arrays

Theory & Syntax Reference

3.1 Declaring Arrays

Arrays are fixed-length structures of elements of identical data type, accessed by index.

1D: DECLARE <name> : ARRAY[lower:upper] OF <type>
2D: DECLARE <name> : ARRAY[r1:r2, c1:c2] OF <type>

DECLARE StudentNames : ARRAY[1:30] OF STRING
DECLARE Scores : ARRAY[1:5] OF INTEGER
DECLARE Grid : ARRAY[1:3,1:3] OF CHAR

3.2 Accessing Elements

Use square brackets. Index expressions must evaluate to a valid integer within bounds.

Python note: Python lists are 0-indexed; Cambridge usually uses lower bound 1.

StudentNames[1] <- "Ali"
Grid[2,3] <- 'X'
StudentNames[n+1] <- StudentNames[n]

3.3 Traversing with Loops

You cannot assign to a group of elements at once — use a FOR loop to process each element individually.

FOR Index <- 1 TO 30
   StudentNames[Index] <- ""
NEXT Index

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

3.4 Two-Dimensional Arrays

A 2D array needs two indices: Array[row, column]. Nested FOR loops traverse all elements.

DECLARE Board : ARRAY[1:3,1:3] OF CHAR
FOR Row <- 1 TO 3
   FOR Col <- 1 TO 3
      Board[Row,Col] <- '-'
   NEXT Col
NEXT Row
✎ Practice Questions
Chapter progress:
0 / 8

Declare a 1D array of 10 integers (indices 1–10):

DECLARE Grid : ARRAY[1:3,1:3] OF CHAR creates:

To set every element of a 30-element array to zero, which is correct?

What is the output of the following code?

DECLARE Nums : ARRAY[1:5] OF INTEGER
FOR i <- 1 TO 5
   Nums[i] <- i
NEXT i
Total <- 0
FOR i <- 1 TO 5
   Total <- Total + Nums[i]
NEXT i
OUTPUT Total

Access row 2, column 3 of array Grid:

ARRAY[1:5] has how many elements?

Copy element at position 3 into position 4 of array Data:

What data type can elements of an array have?

IV

Chapter 4

User-Defined Data Types

Theory & Syntax Reference

4.1 Enumerated Types

Lists all possible values explicitly. Useful for seasons, days, status codes.

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

4.2 Pointer Types

Stores a memory address. The ^ symbol indicates a pointer. Append ^ to dereference (get the value stored at the address).

TYPE TIntPointer = ^INTEGER
DECLARE MyPointer : TIntPointer
MyPointer <- ^SomeInteger   // store address
Value <- MyPointer^          // dereference

4.3 Record Types

Groups related fields of different types under one identifier. Access fields with dot notation.

TYPE StudentRecord
   DECLARE LastName : STRING
   DECLARE FirstName : STRING
   DECLARE DateOfBirth : DATE
   DECLARE YearGroup : INTEGER
ENDTYPE

DECLARE Pupil1 : StudentRecord
Pupil1.LastName <- "Johnson"
Pupil1.YearGroup <- 11

4.4 Set Types

An unordered collection of unique values. Two steps: define the TYPE, then use DEFINE to create an instance.

TYPE LetterSet = SET OF CHAR
DEFINE Vowels ('A','E','I','O','U') : LetterSet

4.5 Using UDDTs

User-defined types can be used in arrays and assigned to each other (same type).

DECLARE Form : ARRAY[1:30] OF StudentRecord

FOR Index <- 1 TO 30
   Form[Index].YearGroup <- Form[Index].YearGroup + 1
NEXT Index

Pupil2 <- Pupil1   // copy entire record
✎ Practice Questions
Chapter progress:
0 / 9

Keyword used to define a user-defined data type:

What does TYPE Season = (Spring, Summer, Autumn, Winter) create?

Dot notation in a RECORD type is used to:

Correct pointer type declaration:

Assign year 2024 to field Year of record variable MyCar:

Keyword that ends a record type definition:

Correct SET type declaration for primary colours:

Can two variables of the same record type be directly assigned?

What does MyPointer <- ^ThisSeason do?

V

Chapter 5

Common Operations

Theory & Syntax Reference

5.1 INPUT and OUTPUT

INPUT <variable> — reads a value from the user.
OUTPUT <value(s)> — displays values. Multiple values separated by commas.

INPUT Answer
OUTPUT Score
OUTPUT "You have ", Lives, " lives left"

5.2 Arithmetic Operators

OpMeaningExampleResult
+Addition5 + 38
-Subtraction10 - 46
*Multiplication6 * 742
/Division (always REAL)7 / 23.5
DIVInteger division7 DIV 23
MODRemainder7 MOD 21

5.3 Relational & Logic Operators

Relational (always return BOOLEAN): > < >= <= = <>

Logic: AND, OR, NOT

IF (Score >= 50) AND (Attempts < 3) THEN
   OUTPUT "Passed"
ENDIF

5.4 String Functions

FunctionReturnsExample
RIGHT(s,n)Last n charsRIGHT("ABCDEFGH",3)"FGH"
LENGTH(s)Integer lengthLENGTH("Happy Days")10
MID(s,x,y)y chars from pos xMID("ABCDEFGH",2,3)"BCD"
LCASE(c)Lower case CHARLCASE('W')'w'
UCASE(c)Upper case CHARUCASE('h')'H'
&Concatenate"Hi" & " " & "there""Hi there"

5.5 Numeric Functions

INT(x) — returns integer part (truncates, does not round).
RAND(x) — random REAL in range 0 to x (exclusive).

INT(27.5415)  // gives 27
INT(-3.7)     // gives -3

// Simulate dice roll 1-6:
Roll <- INT(RAND(6)) + 1
✎ Practice Questions
Chapter progress:
0 / 10

Result of 17 DIV 5:

Result of 17 MOD 5:

Result of 7 / 2:

What does MID("COMPUTING", 4, 3) return?

What does LENGTH("Happy Days") return?

Operator used to concatenate strings:

What does INT(8.9) return?

Output message Score: 42 where 42 is in variable Score:

"Not equal to" operator in Cambridge pseudocode:

What does RIGHT("ABCDEFGH", 3) return?

VI

Chapter 6

Selection

Theory & Syntax Reference

6.1 IF…ENDIF

Executes statements only when condition is TRUE.

IF Score >= 50 THEN
   OUTPUT "Pass"
ENDIF

6.2 IF…ELSE…ENDIF

The ELSE branch runs when the condition is FALSE.

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

6.3 Nested IF

IF statements can nest inside each other. Indentation shows the structure.

IF ChallengerScore > ChampionScore THEN
   IF ChallengerScore > HighestScore THEN
      OUTPUT ChallengerName, " is champion and top scorer"
   ELSE
      OUTPUT ChallengerName, " is the new champion"
   ENDIF
ELSE
   OUTPUT ChampionName, " is still the champion"
ENDIF

6.4 CASE…OF…ENDCASE

Tests a variable against multiple values in sequence. Optional OTHERWISE clause catches unmatched values (must be last).

CASE OF Move
   'W' : Position <- Position - 10
   'S' : Position <- Position + 10
   'A' : Position <- Position - 1
   'D' : Position <- Position + 1
   OTHERWISE : CALL Beep
ENDCASE

6.5 CASE with Range

A CASE clause can match a range of values using TO:

CASE OF Grade
   'A' TO 'C' : OUTPUT "Merit"
   'D' TO 'E' : OUTPUT "Pass"
   OTHERWISE  : OUTPUT "Fail"
ENDCASE
✎ Practice Questions
Chapter progress:
0 / 8

Keyword that closes an IF statement:

Output when X = 8:

IF X > 10 THEN
   OUTPUT "Big"
ELSE
   IF X > 5 THEN
      OUTPUT "Medium"
   ELSE
      OUTPUT "Small"
   ENDIF
ENDIF

Purpose of OTHERWISE in CASE:

Correct CASE syntax:

Output of this code:

Value <- 7
CASE OF Value
   1 TO 3 : OUTPUT "Low"
   4 TO 6 : OUTPUT "Medium"
   7 TO 10 : OUTPUT "High"
   OTHERWISE : OUTPUT "Unknown"
ENDCASE

How do you identify which ENDIF closes which IF in nested code?

What happens if Day has no matching CASE and no OTHERWISE?

Test if a number is between 10 and 20 inclusive:

VII

Chapter 7

Iteration (Repetition)

Theory & Syntax Reference

7.1 FOR…NEXT (Count-controlled)

Repeats a fixed number of times. Optional STEP (positive or negative).

FOR Counter <- 1 TO 5
   OUTPUT Counter
NEXT Counter
// Outputs: 1 2 3 4 5

FOR i <- 10 TO 1 STEP -2
   OUTPUT i
NEXT i
// Outputs: 10 8 6 4 2

7.2 WHILE…ENDWHILE (Pre-condition)

Condition tested before body. If FALSE on first test, body never executes. Use when you may need zero iterations.

WHILE Count < 5
   OUTPUT Count
   Count <- Count + 1
ENDWHILE
// If Count >= 5, nothing is output

7.3 REPEAT…UNTIL (Post-condition)

Body executes at least once — condition tested after body. Loop continues UNTIL condition is TRUE.

REPEAT
   OUTPUT "Enter password:"
   INPUT Password
UNTIL Password = "Secret"
// Always asks at least once

7.4 Choosing the Right Loop

  • FOR — known number of iterations
  • WHILE — unknown iterations, may need zero
  • REPEAT…UNTIL — always need at least one iteration (e.g. input validation)

Python note: FOR → for i in range(), REPEAT…UNTIL → while True: ... if cond: break

✎ Practice Questions
Chapter progress:
0 / 10

How many times does the body execute?

FOR i <- 2 TO 8 STEP 2
   OUTPUT i
NEXT i

WHILE loop to validate input. User enters valid value 5 first time — body executes:

Minimum executions of REPEAT…UNTIL body:

Output of this code:

FOR Counter <- 1 TO 5
   OUTPUT Counter
NEXT Counter

Most appropriate loop when you know exactly how many iterations:

Value of Total after this code?

Total <- 0
FOR n <- 1 TO 5
   Total <- Total + n
NEXT n

REPEAT…UNTIL loop terminates when condition is:

Purpose of STEP in a FOR loop:

How many times does this loop body execute?

X <- 10
WHILE X > 10
   OUTPUT X
   X <- X - 1
ENDWHILE

FOR i <- 5 TO 1 without STEP — what happens?

VIII

Chapter 8

Procedures & Functions

Theory & Syntax Reference

8.1 Procedures

A named block that performs a task. Does not return a value. Called with CALL.

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

CALL Greet("Alice")
CALL Greet("Bob")

8.2 Functions

Returns a single value. Declare return type with RETURNS. Use RETURN inside. Do NOT use CALL — use the function in an expression.

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

Result <- Square(5)
OUTPUT Square(3) + Square(4)

8.3 BYVAL vs BYREF

BYVAL (default): a copy is passed. Changes inside the procedure do NOT affect the original.
BYREF: a reference is passed. Changes DO affect the original. Never pass BYREF to a function.

PROCEDURE Swap(BYREF X : INTEGER, Y : INTEGER)
   Temp <- X
   X <- Y
   Y <- Temp
ENDPROCEDURE

CALL Swap(A, B)  // A and B are modified

8.4 Local Scope

Variables declared inside a procedure/function are local — only accessible within that block.

PROCEDURE Calculate(BYVAL Score : INTEGER)
   // Score is a local copy — original unchanged
   Score <- Score * 2
   OUTPUT Score
ENDPROCEDURE
✎ Practice Questions
Chapter progress:
0 / 9

Call procedure PrintReport with no parameters:

Key difference between PROCEDURE and FUNCTION:

Parameter declared BYREF means:

What is wrong with this call?

CALL GetMax(A, B)

Keyword inside a FUNCTION that sends back the result:

Default parameter passing method:

What does Double(7) return?

FUNCTION Double(n : INTEGER) RETURNS INTEGER
   RETURN n * 2
ENDFUNCTION

PROCEDURE Swap uses BYREF. X=3, Y=7. After CALL Swap(X,Y):

Can parameters be passed BYREF to a FUNCTION?

IX

Chapter 9

File Handling

Theory & Syntax Reference

9.1 Text File Operations

CommandPurpose
OPENFILE f FOR READOpen for reading
OPENFILE f FOR WRITEOpen for writing (overwrites!)
OPENFILE f FOR APPENDAdd to end of file
READFILE f, variableRead next line
WRITEFILE f, dataWrite data to file
CLOSEFILE fClose the file
EOF(f)TRUE if no more lines to read
DECLARE Line : STRING
OPENFILE "data.txt" FOR READ
WHILE NOT EOF("data.txt")
   READFILE "data.txt", Line
   OUTPUT Line
ENDWHILE
CLOSEFILE "data.txt"

9.2 WRITE vs APPEND

WRITE creates a new empty file (existing data is lost). APPEND adds to the end without deleting existing content.

OPENFILE "log.txt" FOR WRITE
WRITEFILE "log.txt", "Session started"
CLOSEFILE "log.txt"

// Add more later without deleting:
OPENFILE "log.txt" FOR APPEND
WRITEFILE "log.txt", "User logged out"
CLOSEFILE "log.txt"

9.3 Random Access Files

Random files allow reading/writing at any position using a file pointer.

CommandPurpose
OPENFILE f FOR RANDOMOpen for random access
SEEK f, addressMove pointer to position
GETRECORD f, variableRead record at pointer
PUTRECORD f, variableWrite record at pointer
OPENFILE "Students.dat" FOR RANDOM
SEEK "Students.dat", 5
GETRECORD "Students.dat", MyStudent
MyStudent.YearGroup <- MyStudent.YearGroup + 1
SEEK "Students.dat", 5
PUTRECORD "Students.dat", MyStudent
CLOSEFILE "Students.dat"
✎ Practice Questions
Chapter progress:
0 / 8

File mode to add data without deleting existing content:

EOF() returns ____ when there are still lines to read:

Correct sequence to read all lines from a text file:

Move pointer to position 10 in random file "Data.dat":

Random access files are opened with mode:

After finishing with a file, a program should:

To write a record to position 5 in a random file:

File opened FOR WRITE already has data. What happens?

X

Chapter 10

Object-Oriented Programming

Theory & Syntax Reference

10.1 Defining a Class

A class is a blueprint for objects. Contains properties (data) and methods (procedures/functions). Public by default unless marked PRIVATE.

CLASS Animal
   PRIVATE Name : STRING
   PRIVATE Sound : STRING

   PUBLIC PROCEDURE NEW(GivenName : STRING, GivenSound : STRING)
      Name <- GivenName
      Sound <- GivenSound
   ENDPROCEDURE

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

ENDCLASS

10.2 Creating Objects

Instantiate a class using <object> <- NEW <ClassName>(params). Calls the constructor.

MyDog <- NEW Animal("Rex", "Woof")
MyCat <- NEW Animal("Whiskers", "Meow")

CALL MyDog.Speak()
CALL MyCat.Speak()

10.3 Inheritance

A child class inherits from a parent using INHERITS. Call the parent constructor with SUPER.NEW(...).

CLASS Dog INHERITS Animal
   PRIVATE Breed : STRING

   PUBLIC PROCEDURE NEW(GivenName : STRING, GivenBreed : STRING)
      SUPER.NEW(GivenName, "Woof")
      Breed <- GivenBreed
   ENDPROCEDURE

   PUBLIC PROCEDURE Fetch()
      OUTPUT Name, " fetches the ball!"
   ENDPROCEDURE

ENDCLASS

MyDog <- NEW Dog("Rex", "Labrador")
CALL MyDog.Speak()  // inherited
CALL MyDog.Fetch()  // own method

10.4 PUBLIC vs PRIVATE

PRIVATE: accessible only within the class.
PUBLIC: accessible from anywhere.
Good practice: make properties PRIVATE, provide PUBLIC getter/setter methods.

CLASS BankAccount
   PRIVATE Balance : REAL

   PUBLIC PROCEDURE NEW(InitialBalance : REAL)
      Balance <- InitialBalance
   ENDPROCEDURE

   PUBLIC PROCEDURE Deposit(Amount : REAL)
      Balance <- Balance + Amount
   ENDPROCEDURE

   PUBLIC FUNCTION GetBalance() RETURNS REAL
      RETURN Balance
   ENDFUNCTION

ENDCLASS
✎ Practice Questions
Chapter progress:
0 / 9

Keyword used to define a class:

A constructor in Cambridge OOP pseudocode is named:

Call parent class constructor from a child class:

Access modifier meaning the property is ONLY accessible within the class:

Correctly create a Cat object (Cat inherits from Pet):

Dog INHERITS Animal. Animal has Speak(). Can a Dog object call Speak()?

Call method SetName on object Player1:

What is PRIVATE Balance : REAL inside a class?

Purpose of a getter method like GetBalance():