Cambridge IGCSE 0478 · O-Level 2210 · A-Level 9618

Pseudocode Cheat Sheet

Every syntax rule you need for your Cambridge exam — in one place. Bookmark this page.

📋 Jump to Section

Data Types

INTEGER
Whole numbers
e.g. -5, 0, 42
REAL
Decimal numbers
e.g. 3.14, -2.5
STRING
Text values
e.g. "Hello"
BOOLEAN
TRUE or FALSE only
CHAR
Single character
e.g. 'A', '5'

Variables & Constants

Declare a Variable
DECLARE Score : INTEGER
DECLARE Name : STRING
DECLARE Price : REAL
DECLARE Flag : BOOLEAN
Assign a Value (← arrow)
Score ← 0
Name ← "Alice"
Price ← 9.99
Flag ← TRUE
Declare a Constant
CONSTANT MaxScore ← 100
CONSTANT PI ← 3.14159
⚠️ Exam tip: Always use (left arrow) for assignment, never =. Use DECLARE before first use. Constants use CONSTANT keyword.

Operators

ArithmeticSymbol
Addition+
Subtraction-
Multiplication*
Division (real)/
Integer divisionDIV
Modulus (remainder)MOD
ComparisonSymbol
Equal to=
Not equal to<>
Less than<
Greater than>
Less than or equal<=
Greater than or equal>=
Logical Operators
AND   // Both conditions must be TRUE
OR    // At least one condition must be TRUE
NOT   // Reverses TRUE/FALSE

INPUT & OUTPUT

OUTPUT "Enter your name:"
INPUT Name
OUTPUT "Hello, ", Name
OUTPUT "Your score is: ", Score

Conditional Statements

Simple IF
IF Score > 50
    THEN
        OUTPUT "Pass"
ENDIF
IF...ELSE
IF Score > 50
    THEN
        OUTPUT "Pass"
    ELSE
        OUTPUT "Fail"
ENDIF
Nested IF
IF Score > 70
    THEN
        OUTPUT "A"
    ELSE
        IF Score > 50
            THEN
                OUTPUT "B"
        ENDIF
ENDIF
CASE OF (Switch Statement)
CASE OF Grade
    "A" : OUTPUT "Excellent"
    "B" : OUTPUT "Good"
    "C" : OUTPUT "Average"
    OTHERWISE : OUTPUT "Below average"
ENDCASE

FOR Loop (Count-Controlled)

Basic FOR Loop
DECLARE i : INTEGER

FOR i ← 1 TO 10
    OUTPUT i
NEXT i
FOR with STEP
DECLARE i : INTEGER

FOR i ← 0 TO 10 STEP 2
    OUTPUT i
NEXT i
// Outputs: 0 2 4 6 8 10
⚠️ Exam tip: Always DECLARE the loop counter variable. Close with NEXT i (not ENDFOR). Use STEP for non-1 increments.

WHILE Loop (Pre-Condition)

DECLARE Count : INTEGER
Count ← 1

WHILE Count <= 5
    OUTPUT Count
    Count ← Count + 1
ENDWHILE

// Condition checked BEFORE the loop body
// May never execute if condition is FALSE initially

REPEAT...UNTIL (Post-Condition)

DECLARE Input : INTEGER

REPEAT
    OUTPUT "Enter a value between 1 and 10:"
    INPUT Input
UNTIL Input >= 1 AND Input <= 10

// Condition checked AFTER the loop body
// Always executes at LEAST once — ideal for input validation

Arrays (1D & 2D)

1D Array Declaration
// Declares array of 5 INTEGERs
// Index goes from 1 to 5
DECLARE Scores[1:5] : INTEGER

// Assign & access values
Scores[1] ← 85
Scores[2] ← 91
OUTPUT Scores[1]
2D Array Declaration
// 3 rows, 4 columns
DECLARE Grid[1:3, 1:4] : INTEGER

// Access: [row, column]
Grid[2, 3] ← 42
OUTPUT Grid[2, 3]
Traverse 1D Array with FOR Loop
DECLARE i : INTEGER
FOR i ← 1 TO 5
    OUTPUT Scores[i]
NEXT i
Traverse 2D Array with Nested FOR Loops
DECLARE row, col : INTEGER
FOR row ← 1 TO 3
    FOR col ← 1 TO 4
        OUTPUT Grid[row, col]
    NEXT col
NEXT row
⚠️ Exam tip: Cambridge pseudocode uses 1-based indexing (arrays start at index 1, not 0). Always declare array bounds using [1:n] format.

Functions (Return a Value)

// Define a function
FUNCTION CalculateArea(Length : REAL, Width : REAL) RETURNS REAL
    RETURN Length * Width
ENDFUNCTION

// Call a function — assign return value
DECLARE Area : REAL
Area ← CalculateArea(5.0, 3.0)
OUTPUT Area  // Outputs: 15.0

Procedures (No Return Value)

// BYVAL — changes don't affect original variable
PROCEDURE ShowGreeting(Name BYVAL : STRING)
    OUTPUT "Hello, ", Name
ENDPROCEDURE

// BYREF — changes DO affect original variable
PROCEDURE DoubleValue(Num BYREF : INTEGER)
    Num ← Num * 2
ENDPROCEDURE

// Call a procedure with CALL keyword
CALL ShowGreeting("Alice")
CALL DoubleValue(Score)

String Operations

String Functions
// Get length of string
LENGTH("Hello")      // → 5

// Get substring
SUBSTRING("Hello", 2, 3)  // → "ell"

// Convert to uppercase
UCASE("hello")      // → "HELLO"

// Convert to lowercase
LCASE("HELLO")      // → "hello"
Math Functions
// Random integer between 1 and n
RANDOM(10)           // → 1 to 10

// Round to n decimal places
ROUND(3.567, 2)      // → 3.57

// Integer part only
INT(3.9)              // → 3

// String concatenation
"Hello" & " World"  // → "Hello World"

Test Your Pseudocode Instantly

Use any of the syntax above in our free online compiler. See your code run in real time.

▶ Open Free Compiler

Explore Topic-Specific Guides:

Variables & Types Loops Conditionals Arrays Functions Strings