Pseudocode Overview
This page can serve as a quick lookup for the CIE pseudocode examples as given in the specification. ALWAYS refer to the CAIE Pseudocode Teacher Guide as that will always hold up-to-date content for your exam.
Data Types (10.1)
Pseudocode will use the following data types:
INTEGER
REAL
CHAR
STRING
BOOLEAN
DATE
ARRAY
FILE
Arrays (10.2)
Given pseudocode will use the following structures:
DECLARE <identifier> : ARRAY[<lbound>:<ubound>] OF <datatype>
DECLARE <identifier> : ARRAY[<lbound1>:<ubound1>,[<lbound2>:<ubound2>] OF <datatype>
Files (10.3)
Use pseudocode for file handling:
OPENFILE <filename> FOR READ/WRITE/APPEND // Open file (understand the difference between various file modes)
READFILE <filename>,<string variable> // Read a line of text from the file
WRITEFILE <filename>,<string variable> // Write a line of text to the file
CLOSEFILE <filename> // Close file
EOF(<filename>) // function to test for the end of the file - returns TRUE or FALSE
Programming Basics (9-11)
Given pseudocode will use the following structures:
DECLARE <identifier> : <data type> // declaration
CONSTANT <identifier> = <value>
<identifier> ← <value> or <expression> // assignment
INPUT <identifier>
OUTPUT <string> // this is a literal string, encased in quotation marks ""
OUTPUT <identifier(s)>
Concatenation uses '&' symbol now, rather than comma, as in previous specification.
Selection (11.2)
Use an ‘IF’ structure including the ‘ELSE’ clause and nested IF statements. Given pseudocode will use the following structure:
IF <condition>
THEN
<statement(s)>
ENDIF
–– or, including an ‘else’ clause:
IF <condition>
THEN
<statement(s)>
ELSE
<statement(s)>
ENDIF
Use a ‘CASE’ structure. Given pseudocode will use the following structure:
CASE OF <identifier>
<value 1>: <statement>
<value 2>: <Statement>
...
ENDCASE
–– alternatively, using optional OTHERWISE:
CASE OF <identifier>
<value 1>: <statement>
<value 2>: <Statement>
...
OTHERWISE <statement>
ENDCASE
Iteration (11.2)
Use a ‘count-controlled’ loop. Given pseudocode will use the following structure:
FOR <identifier> ← <value1> TO <value2>
<statement(s)>
NEXT <identifier>
–– alternatively:
FOR <identifier> ← <value1> TO <value2> STEP <value3>
<statement(s)>
NEXT <identifier>
Use a ‘post-condition’ loop. Given pseudocode will use the following structure:
REPEAT
<statement(s)>
UNTIL <condition>
Use a ‘pre-condition’ loop. Given pseudocode will use the following structure:
WHILE <condition>
<statement(s)>
ENDWHILE
Procedures/Functions (Structured Programming) (11.3)
Given pseudocode will use the following structure for procedure definitions:
PROCEDURE <identifier>
<statement(s)>
ENDPROCEDURE
Show understanding of passing parameters by reference:
PROCEDURE <identifier> (BYREF <identifier>: <datatype>)
<statement(s)>
ENDPROCEDURE
show understanding of passing parameters by value:
PROCEDURE <identifier> (BYVALUE <identifier>: <datatype>)
<statement(s)>
ENDPROCEDURE
A call is made to the procedure using CALL <identifier> ()
Given pseudocode will use the following structure for function definitions:
FUNCTION <identifier> RETURNS <data type> // function has no parameters
<statement(s)>
ENDFUNCTION
FUNCTION <identifier> (<identifier>: <data type>) RETURNS <data type> // function has one or more parameters
<statement(s)>
ENDFUNCTION
–– a function is used in an expression, for example:
x ← SQRT(n)
WHILE NOT EOF(<filename>)