Skip to main content

The Ultimate Pseudocode Syntax Guide for Paper 2

By Prof. David Chen, CS Examiner·Updated April 18, 2026
A snippet of CAIE-compliant pseudocode showing a FOR loop writing to a 1D array.

What are the three main constructs of programming?

1) Sequence: Code runs line by line from top to bottom. 2) Selection: Code branches using IF/THEN/ELSE or CASE statements. 3) Iteration: Code repeats using FOR, WHILE, or REPEAT-UNTIL loops.

Paper 2 (Problem-solving and Programming) is built entirely around CAIE's specific flavor of pseudocode. If you write Python or Java code in the exam, you will lose marks for not using the standardized syntax. This cheat sheet from our Ultimate O-Level Computer Science Guide gives you the exact syntax rules.

1. Declaring Variables and Assignment

Before you use a variable in pseudocode, you generally must DECLARE it and assign it a data type (INTEGER, REAL, STRING, CHAR, BOOLEAN).

DECLARE TotalScore : INTEGER
DECLARE Average : REAL
DECLARE PlayerName : STRING

TotalScore <- 0
PlayerName <- "John"
OUTPUT "Hello, ", PlayerName
💡 Tutor's Tip
The Assignment Arrow: Never use an equals sign to store a value. You must use the left-pointing arrow <-. The equals sign is strictly reserved for comparing things (e.g. IF Score = 100).

2. Selection (IF and CASE statements)

Selection allows your code to make decisions. Every IF statement must end with an ENDIF.

The IF/THEN/ELSE Structure

IF Mark >= 50 THEN
    OUTPUT "Pass!"
ELSE
    OUTPUT "Fail. Try again."
ENDIF

The CASE Structure

If you have many different options (like a menu system), an IF statement gets very messy and nested. Use a CASE statement instead.

CASE OF UserInput
    1 : OUTPUT "Starting Game"
    2 : OUTPUT "Loading Save"
    3 : OUTPUT "Exiting"
    OTHERWISE : OUTPUT "Invalid option chosen"
ENDCASE

3. Iteration (The 3 Types of Loops)

Iteration means repeating a sequence of code. You must choose the right loop for the right scenario.

1. The FOR Loop (Count-Controlled)

Use this when you know EXACTLY how many times the loop needs to run (e.g., asking exactly 10 students for their age). It automatically increments the counter.

FOR Counter <- 1 TO 10
    OUTPUT "Enter age:"
    INPUT Age
NEXT Counter

2. The WHILE Loop (Pre-Condition)

Use this when you don't know how many times the loop will run. High risk of infinite loops! The condition is checked at the start. If it is false immediately, the loop runs ZERO times.

WHILE Password <> "Secret123" DO
    OUTPUT "Wrong password, try again:"
    INPUT Password
ENDWHILE

3. The REPEAT-UNTIL Loop (Post-Condition)

Checks the condition at the END. Therefore, it is guaranteed to run AT LEAST ONCE. Excellent for user input validation.

REPEAT
    OUTPUT "Enter a number between 1 and 10:"
    INPUT Num
UNTIL Num >= 1 AND Num <= 10
Prof. David Chen📋 From the Desk of Prof. David Chen
When using standard logic symbols, remember that 'Not Equal To' is written as <>. Do not write != like in Python/JavaScript.

Frequently Asked Questions

What is the difference between = and <- in Pseudocode?
The equals sign '=' is for comparisons. The arrow '<-' is for assigning a value to a variable.
What is the difference between a WHILE loop and a REPEAT-UNTIL loop?
WHILE checks the condition before running (may run 0 times). REPEAT-UNTIL checks at the end (will run at least 1 time).
How do you declare a 1D Array in O-Level Pseudocode?
DECLARE ArrayName[Start:End] OF DataType. E.g., DECLARE Names[1:50] OF STRING.
Why must you indent pseudocode?
Indentation clearly defines the blocks of code inside loops and IF statements for the examiner.

Stop Guessing, Start Scoring

Get instant access to 500+ CAIE-aligned practice questions, worked solutions, and AI-powered mock exams across all O-Level subjects.

Related Computer Science Articles