0984

Pseudocode and Flowcharts

Algorithm Design and Problem Solving · 4 question types

Exam Frequency Analysis

Past paper frequency (2018 to 2024)

This topic accounts for approximately 11% of your exam marks.

stable
Medium
Stable11%

The most marks-dense topic. Both papers test pseudocode writing and trace tables every sitting.

CIE pseudocode is its own style. It is not real Python or any other language. The rules are deliberately simple, so any student can read or write it regardless of which language they have learned. Marks are lost if you write things like print(...) with brackets when the question asks for pseudocode.

Variables and assignment

Variables hold values. In CIE pseudocode the arrow operator is the only assignment operator. A single = is not assignment in CIE pseudocode; it means equality (comparison), so do not use it to give a variable a value.

Total ← 0
Count ← Count + 1
Name ← "Alice"
IsFinished ← FALSE

Variables are also declared with a data type using DECLARE:

DECLARE Score : INTEGER
DECLARE Name : STRING
DECLARE IsFinished : BOOLEAN
DECLARE Price : REAL

Input and output

Two clean keywords, with no brackets:

INPUT Age
OUTPUT "Welcome to the site, ", Name

IF-THEN-ELSE selection

A standard two-branch selection:

IF Age >= 18
  THEN
    OUTPUT "Welcome to the site"
  ELSE
    OUTPUT "Sorry, this site is for over-18s only"
ENDIF

Selections can be nested to test more than two cases:

IF Score >= 70
  THEN
    Grade ← "A"
  ELSE
    IF Score >= 60
      THEN
        Grade ← "B"
      ELSE
        Grade ← "C"
    ENDIF
ENDIF

For more than a handful of branches, CASE OF ... OTHERWISE ... ENDCASE is cleaner:

CASE OF Day
   1 : OUTPUT "Monday"
   2 : OUTPUT "Tuesday"
   3 : OUTPUT "Wednesday"
   4 : OUTPUT "Thursday"
   5 : OUTPUT "Friday"
   OTHERWISE OUTPUT "Weekend"
ENDCASE

Loops

Three loop constructs are tested by the syllabus; they are compared in section 5.

FOR i ← 1 TO 10
   OUTPUT i
NEXT i

WHILE NotFinished = TRUE DO
   INPUT Answer
   IF Answer = "stop"
     THEN
       NotFinished ← FALSE
   ENDIF
ENDWHILE

REPEAT
   INPUT Number
UNTIL Number > 0

Arrays

Arrays hold a list of values of the same type:

DECLARE Scores : ARRAY[1:10] OF INTEGER
Scores[1] ← 75
Scores[2] ← 88
OUTPUT Scores[1]

CIE arrays are usually 1-indexed, with the size given as [1:10]. Some other syntaxes use [10].

Arithmetic operators

OperatorMeaning
+ - * /Plus, minus, multiply, divide
DIV(a, b)Integer division: the quotient of a divided by b with the fractional part discarded, so DIV(17, 5) returns 3
MOD(a, b)The remainder of a divided by b, so MOD(17, 5) returns 2

Comparison operators

OperatorMeaning
=Equal to
<>Not equal to
< >Less than, greater than
<= >=Less than or equal, greater than or equal

Logical operators

OperatorMeaning
ANDBoth conditions are true
ORAt least one condition is true
NOTThe single condition is not true

Useful string functions

FunctionWhat it does
LENGTH(s)Returns the number of characters in s
SUBSTRING(s, start, length)Returns part of s starting at position start, for length characters
UCASE(s)Returns s with every letter in uppercase
LCASE(s)Returns s with every letter in lowercase

Procedures and functions

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

CALL Greet("Alice")
FUNCTION Square(Value : INTEGER) RETURNS INTEGER
   RETURN Value * Value
ENDFUNCTION

Result ← Square(5)

These are covered in detail in topic 24 (Procedures and Functions).

Common pseudocode pitfalls

  • Do not use real-language syntax: avoid print(), input(), range(). Stick to OUTPUT, INPUT, FOR ... NEXT.
  • Always close compound statements: IF needs ENDIF; WHILE needs ENDWHILE; FOR needs NEXT <counter>.
  • Indent inside compound statements to make the structure clear; examiners reward readable layout.
  • Use UPPERCASE for keywords to make them stand out (IF, THEN, WHILE, DO, NEXT).
  • Use clear variable names that describe what they store (StudentScore, not x).