IGCSE Computer Science Pseudocode Prep
IGCSE Computer Science Pseudocode Prep
IGCSE Computer Science Pseudocode Prep
Cambridge International
AS & A Level
Computer Science 9618
Use this guide for exams in 2026.
Version 1
For the purposes of screen readers, any mention in this document of Cambridge IGCSE
refers to Cambridge International General Certificate of Secondary Education.
Quality management
Cambridge International is committed to providing exceptional quality. In line with this commitment, our
quality management system for the provision of international education programmes and qualifications
programmes for students aged 5 to 19 is independently certified as meeting the internationally recognised
standard, ISO 9001:2015. Learn more at www.cambridgeinternational.org/about-us/our-standards/
3 Arrays...........................................................................................................................10
3.1 Declaring arrays 10
3.2 Using arrays 10
5 Common operations...................................................................................................15
5.1 Input and output 15
5.2 Arithmetic operations 15
5.3 Relational operations 16
5.4 Logic operators 16
5.5 String functions and operations 16
5.6 Numeric functions 17
6 Selection......................................................................................................................18
6.1 IF statements 18
6.2 CASE statements 19
7 Iteration (repetition)................................................................................................... 20
7.1 Count-controlled (FOR) loops 20
7.2 Post-condition (REPEAT) loops 20
7.3 Pre-condition (WHILE) loops 21
The following information sets out how pseudocode will appear within the examined components and is
provided to allow you to give learners familiarity before the exam.
1.2 Indentation
Lines are indented (usually by three spaces) to indicate that they are contained within a statement in a previous
line. In cases where line numbering is used, this indentation may be omitted. Every effort will be made to
make sure that code statements are not longer than a line of text unless this is absolutely necessary. Where
necessary, continuation lines will be aligned to maximise readability.
1.3 Case
Keywords are in upper-case, e.g. IF, REPEAT, PROCEDURE. (Different keywords are explained in later sections
of this guide.)
Identifiers are in mixed case (sometimes referred to as camelCase or Pascal case) with upper-case letters
indicating the beginning of new words, for example NumberOfPlayers.
Meta-variables – symbols in the pseudocode that should be substituted by other symbols are enclosed in
angled brackets < > (as in Backus-Naur Form). This is also used in this guide.
Example – meta-variables
REPEAT
<statement(s)>
UNTIL <condition>
Line numbers are consecutive, unless numbers are skipped to indicate that part of the code is missing. This will
also be clearly stated.
Each line representing a statement is numbered. However, when a statement runs over one line of text, the
continuation lines are not numbered.
1.5 Comments
Comments are preceded by two forward slashes //. The comment continues until the end of the line. For
multi‑line comments, each line is preceded by //.
Normally the comment is on a separate line before, and at the same level of indentation as, the code it refers
to. Occasionally, however, a short comment that refers to a single line may be at the end of the line to which it
refers.
Example – comments
2.2 Literals
Literals of the above data types are written as follows:
2.3 Identifiers
Identifiers (the names given to variables, constants, procedures and functions) are in mixed case. They can only
contain letters (A–Z, a–z), digits (0–9) and the underscore character ( _ ). They must start with a letter and not a
digit. Accented letters should not be used.
It is good practice to use identifier names that describe the variable, procedure or function they refer to. Single
letters may be used where these are conventional (such as i and j when dealing with array indices, or X and Y
when dealing with coordinates) as these are made clear by the convention.
Keywords identified elsewhere in this guide should never be used as variable names.
Identifiers should be considered case insensitive, for example, Countdown and CountDown should not be
used as separate variable names.
2.5 Constants
It is good practice to use constants if this makes the pseudocode more readable, as an identifier is more
meaningful in many cases than a literal. It also makes the pseudocode easier to update if the value of the
constant changes.
Constants are normally declared at the beginning of a piece of pseudocode (unless it is desirable to restrict the
scope of the constant).
Constants are declared by stating the identifier and the literal value in the following format:
Only literals can be used as the value of a constant. A variable, another constant or an expression must never
be used.
2.6 Assignments
The assignment operator is ← .
<identifier> ← <value>
The identifier must refer to a variable (this can be an individual element in a data structure such as an array or a
user defined data type). The value may be any expression that evaluates to a value of the same data type as the
variable.
Example – assignments
Counter ← 0
Counter ← Counter + 1
TotalToPay ← NumberOfHours * HourlyRate
3 Arrays
Syllabus requirements
The Cambridge International AS & A Level syllabus (9618) requires candidates to understand and use both
one-dimensional and two-dimensional arrays.
DECLARE <identifier>:ARRAY
[<lower1>:<upper1>,<lower2>:<upper2>]
OF <data type>
StudentNames[1] ← "Ali"
NoughtsAndCrosses[2,3] ← ꞌXꞌ
StudentNames[n+1] ← StudentNames[n]
Arrays can be used in assignment statements (provided they have same size and data type). The following is
therefore allowed:
SavedGame ← NoughtsAndCrosses
A statement should not refer to a group of array elements individually. For example, the following construction
should not be used.
Instead, an appropriate loop structure is used to assign the elements individually. For example:
FOR Index ← 1 TO 30
StudentNames[Index] ← ""
NEXT Index
Syllabus requirements
The Cambridge International AS & A Level syllabus (9618) requires candidates to understand that data
structures that are not available in a particular programming language need to be constructed from the data
structures that are built-in within the language. User-defined data types need to be defined. The syllabus
requires candidates to use and define non-composite data types such as enumerated and pointer and
composite data types such as record, set, class/object. Abstract Data Types (ADTs) stack, queue, linked
list, dictionary and binary tree are also defined as composite data types.
The ^ shows that the variable is a pointer and the data type indicates the type of the data stored in the memory
location.
Declaration of a variable of pointer type does not require the ^ (caret) symbol to be used.
TYPE <identifier1>
DECLARE <identifier2> : <data type>
DECLARE <identifier3> : <data type>
...
ENDTYPE
TYPE StudentRecord
DECLARE LastName : STRING
DECLARE FirstName : STRING
DECLARE DateOfBirth : DATE
DECLARE YearGroup : INTEGER
DECLARE FormGroup : CHAR
ENDTYPE
Variables of a user-defined data type can be assigned to each other. Individual data items are accessed using
dot notation.
This pseudocode uses the user-defined types StudentRecord, Season and TIntPointer defined in the
previous section.
Pupil1.LastName ← "Johnson"
Pupil1.Firstname ← "Leroy"
Pupil1.DateOfBirth ← 02/01/2005
Pupil1.YearGroup ← 6
Pupil1.FormGroup ← ꞌAꞌ
Pupil2 ← Pupil1
FOR Index ← 1 TO 30
Form[Index].YearGroup ← Form[Index].YearGroup + 1
NEXT Index
ThisSeason ← Spring
MyPointer ← ^ThisSeason
NextSeason ← MyPointer^ + 1
// access the value stored at the memory address
5 Common operations
INPUT <identifier>
The identifier should be a variable (that may be an individual element of a data structure such as an array, or a
custom data type).
OUTPUT <value(s)>
Several values, separated by commas, can be output using the same command.
INPUT Answer
OUTPUT Score
OUTPUT "You have ", Lives, " lives left"
+ Addition
– Subtraction
* Multiplication
/ Division (The resulting value should be of data type REAL, even if the operands are integers.)
DIV Integer division: Used to find the quotient (integer number before the decimal point) after division.
MOD or Modulus: The remainder that is left over when one number is divided by another.
Multiplication and division have higher precedence over addition and subtraction (this is the normal
mathematical convention). However, it is good practice to make the order of operations in complex expressions
explicit by using parentheses.
= Equal to
In complex expressions it is advisable to use parentheses to make the order of operations explicit.
In complex expressions it is advisable to use parentheses to make the order of operations explicit.
The Cambridge International AS & A Level syllabus (9618) specifically requires candidates to know string
manipulation functions in their chosen programming language. Pseudocode string manipulation functions
will always be provided in examinations. Some basic string manipulation functions are given here.
Each function returns an error if the function call is not properly formed.
Where string operations (such as concatenation, searching and splitting) are used in a programming language,
these should be explained clearly, as they vary considerably between systems.
Where functions in programming languages are used to format numbers as strings for output, their use should
also be explained.
6 Selection
6.1 IF statements
IF statements may or may not have an ELSE clause.
IF <condition> THEN
<statement(s)>
ENDIF
IF <condition> THEN
<statement(s)>
ELSE
<statement(s)>
ENDIF
Note, due to space constraints, the THEN and ELSE clauses may only be indented by two spaces rather than
three. (They are, in a sense, a continuation of the IF statement rather than separate statements).
CASE OF <identifier>
<value 1> :
<statement1>
<statement2>
...
<value 2> :
<statement1>
<statement2>
...
...
ENDCASE
CASE OF <identifier>
<value 1> :
<statement1>
<statement2>
...
<value 2> :
<statement1>
<statement2>
...
OTHERWISE :
<statement1>
<statement2>
...
ENDCASE
<value1> TO <value2> :
<statement1>
<statement2>
...
Note that the CASE clauses are tested in sequence. When a case that applies is found, its statement is
executed and the CASE statement is complete. Control is passed to the statement after the ENDCASE. Any
remaining cases are not tested.
If present, an OTHERWISE clause must be the last case. Its statement will be executed if none of the preceding
cases apply.
INPUT Move
CASE OF Move
ꞌWꞌ : Position ← Position − 10
ꞌSꞌ : Position ← Position + 10
ꞌAꞌ : Position ← Position − 1
ꞌDꞌ : Position ← Position + 1
OTHERWISE : CALL Beep
ENDCASE
7 Iteration (repetition)
The identifier must be a variable of data type INTEGER, and the values should be expressions that evaluate to
integers.
The variable is assigned each of the integer values from value1 to value2 inclusive, running the statements
inside the FOR loop after each assignment. If value1 = value2 the statements will be executed once, and if
value1 > value2 the statements will not be executed.
It is good practice to repeat the identifier after NEXT, particularly with nested FOR loops.
The increment must be an expression that evaluates to an integer. In this case the identifier will be assigned
the values from value1 in successive increments of increment until it reaches value2. If it goes past
value2, the loop terminates. The increment can be negative.
Total ← 0
FOR Row ← 1 TO MaxRow
RowTotal ← 0
FOR Column ← 1 TO 10
RowTotal ← RowTotal + Amount[Row, Column]
NEXT Column
OUTPUT "Total for Row ", Row, " is ", RowTotal
Total ← Total + RowTotal
NEXT Row
OUTPUT "The grand total is ", Total
REPEAT
<statement(s)>
UNTIL <condition>
The statements in the loop will be executed at least once. The condition is tested after the statements are
executed and if it evaluates to TRUE the loop terminates, otherwise the statements are executed again.
REPEAT
OUTPUT "Please enter the password"
INPUT Password
UNTIL Password = "Secret"
WHILE <condition>
<statement(s)>
ENDWHILE
The condition is tested before the statements, and the statements will only be executed if the condition
evaluates to TRUE. After the statements have been executed the condition is tested again. The loop terminates
when the condition evaluates to FALSE.
The statements will not be executed if, on the first test, the condition evaluates to FALSE.
Syllabus requirements
The definition and use of procedures and functions is explicitly required in the Cambridge International
AS & A Level syllabus (9618). Any pseudocode functions used in an examination will be defined.
PROCEDURE <identifier>()
<statement(s)>
ENDPROCEDURE
The <identifier> is the identifier used to call the procedure. Where used, param1, param2 etc. are
identifiers for the parameters of the procedure. These will be used as variables in the statements of the
procedure.
CALL <identifier>()
When parameters are used, value1, value2... must be of the correct data type and in the same sequence
as in the definition of the procedure.
Unless otherwise stated, it should be assumed that parameters are passed by value. (See section 8.3).
PROCEDURE DefaultSquare()
CALL Square(100)
ENDPROCEDURE
FUNCTION <identifier>(
<param1> : <data type>,
<param2> : <data type>...) RETURNS <data type>
<statement(s)>
ENDFUNCTION
The keyword RETURN is used as one of the statements within the body of the function to specify the value to
be returned. Normally, this will be the last statement in the function definition, however, if the RETURN statement
is in the body of the function its execution is immediate and any subsequent lines of code are omitted.
Because a function returns a value that is used when the function is called, function calls are not complete
program statements. The keyword CALL should not be used when calling a function. Functions should only
be called as part of an expression. When the RETURN statement is executed, the value returned replaces the
function call in the expression and the expression is then evaluated.
If the method for passing parameters is not specified, passing by value is assumed. How this should be called
and how it operates has already been explained in Section 8.1.
9 File handling
A file must be opened in a specified mode before any file operations are attempted. This is written as follows:
The file identifier may be a literal string containing the file names, or a variable of type STRING that has been
assigned the file name.
Data is read from the file (after the file has been opened in READ mode) using the READFILE command as
follows:
The variable should be of data type STRING. When the command is executed, the next line of text in the file
is read and assigned to the variable.
The function EOF is used to test whether there are any more lines to be read from a given file. It is called as
follows:
EOF(<file identifier>)
This function returns TRUE if there are no more lines to read (or if an empty file has been opened in READ
mode) and FALSE otherwise.
Data is written into the file (after the file has been opened in WRITE or APPEND mode) using the WRITEFILE
command as follows:
Files should be closed when they are no longer needed using the CLOSEFILE command as follows:
This example uses the operations together, to copy all the lines from FileA.txt to FileB.txt, replacing
any blank lines by a line of dashes.
Random files are opened using the RANDOM file mode as follows:
As with text files, the file identifier will normally be the name of the file.
The address should be an expression that evaluates to an integer which indicates the location of a record to be
read or written. This is usually the number of records from the beginning of the file. It is good practice to explain
how the addresses are computed.
The command GETRECORD should be used to read the record at the file pointer:
When this command is executed, the record that is read is assigned to the variable which must be of the
appropriate data type for that record (usually a user-defined type).
The command PUTRECORD is used to write a record into the file at the file pointer:
When this command is executed, the data in the variable is inserted into the record at the file pointer. Any data
that was previously at this location will be replaced.
The records from positions 10 to 20 of a file StudentFile.Dat are moved to the next position and a new
record is inserted into position 10. The example uses the user-defined type Student defined in Section 4.1.
NewPupil.LastName ← "Johnson"
NewPupil.Firstname ← "Leroy"
NewPupil.DateOfBirth ← 02/01/2005
NewPupil.YearGroup ← 6
NewPupil.FormGroup ← ꞌAꞌ
SEEK "StudentFile.Dat", 10
PUTRECORD "StudentFile.Dat", NewPupil
CLOSEFILE "StudentFile.dat"
10 Object-oriented Programming
Example code
Player.SetAttempts(5)
OUTPUT Player.GetAttempts()
CLASS Pet
PRIVATE Name : STRING
PUBLIC PROCEDURE NEW(GivenName : STRING)
Name ← GivenName
ENDPROCEDURE
ENDCLASS
Inheritance is denoted by the INHERITS keyword; superclass/parent class methods will be called using the
keyword SUPER, for example:
For example:
-, 16 GETRECORD, 27
←, 10 IF, 19
*, 16 INHERITS, 29
/, 16 INPUT, 16
//, 7 INT, 18
+, 16 INTEGER, 8
<, 17 LCASE, 18
<=, 17 LENGTH, 17
<>, 17 MID, 18
=, 17 MOD, 16
>, 17 NEXT, 21
>=, 17 NEW, 29
^ (caret), 13 NOT, 17
&, 18 OPENFILE, 26
AND, 17 OR, 17
APPEND, 26 OTHERWISE, 20
ARRAY, 11 OUTPUT, 16
BOOLEAN, 8 PROCEDURE, 23
BYREF, 25 PRIVATE, 29
BYVAL, 25 PUBLIC, 29
CALL, 23 PUTRECORD, 28
CASE OF, 20 RAND, 18
CHAR, 8 RANDOM (files), 27
CLASS, 29 READ, 26
CLOSEFILE, 26 READFILE, 26
CONSTANT, 9 REAL, 8
DATE, 8 REPEAT, 21
DECLARE, 9 RETURN, 24
DIV, 16 RETURNS, 24
ELSE, 19 RIGHT, 17
ENDCASE, 20 SEEK, 27
ENDCLASS, 29 STEP, 21
ENDFUNCTION, 24 STRING, 8
ENDIF, 19 SUPER, 29
ENDPROCEDURE, 23 THEN, 19
ENDTYPE, 14 TRUE, 8
ENDWHILE, 22 TYPE, 13
EOF, 26 UCASE, 18
FALSE, 8 UNTIL, 21
FOR ... TO, 21 WHILE, 22
FOR (file handling), 26 WRITE, 26
FUNCTION, 24 WRITEFILE, 26
Cambridge Assessment International Education, The Triangle Building, Shaftesbury Road, Cambridge, CB2 8EA, United Kingdom
t : +44 (0)1223 553554 email : [email protected] www.cambridgeinternational.org