Guide 2 of 7

Conditional Statements

Algorithms need to make decisions. Learn how to route the flow of your program using standard IF statements and CASE structures for your Cambridge exams.

Exam Strategy: IF vs. CASE OF

In the IGCSE 0478 and A-Level 9618 syllabi, examiners expect you to choose the most efficient logical structure. While you *could* use a giant chain of nested IF statements for everything, it's often poor practice.

Use IF...THEN: When evaluating complex boolean logic, ranges (e.g., Score >= 50 AND Score <= 100), or comparing multiple different variables at once.
Use CASE OF: When checking a single variable against many specific, discrete values (e.g., a Main Menu where the user inputs 1, 2, or 3). Examiners love CASE OF because it proves you know how to write clean, readable code.

Python vs. Pseudocode Conditionals

If you learned Python first, the structure of conditional statements in pseudocode can feel extremely repetitive. You must remember to strictly close every single block you open.

Concept 🐍 Python (Wrong for Exams) 📘 Cambridge Pseudocode (Correct)
Basic IF Statement if score == 10:
  print("Win")
IF Score = 10 THEN
  OUTPUT "Win"
ENDIF
Else If Condition elif score > 5:
  print("Close")
ELSE IF Score > 5 THEN
  OUTPUT "Close"
Multiple Choices match menu_choice:
  case 1:
    play()
CASE OF MenuChoice
  1 : CALL Play()
ENDCASE

1. The IF...THEN...ELSE Statement

The IF statement checks a logical condition. If it is TRUE, one block of code runs. If it is FALSE, the program can optionally run an ELSE block. Every IF statement must be closed explicitly with an ENDIF.

IF Statement Syntax
DECLARE ExamScore : INTEGER
ExamScore ← 85

IF ExamScore >= 50 THEN
    OUTPUT "You passed the exam!"
ELSE
    OUTPUT "You failed. Please retake."
ENDIF

2. Nested IF Statements

You can place an IF statement inside another IF statement to check multiple specific conditions in sequence. Indentation is crucial here so the examiner (and the compiler) can track which ENDIF belongs to which IF.

Nested IF Syntax
IF ExamScore >= 90 THEN
    OUTPUT "Grade: A*"
    IF ExamScore >= 80 THEN
        OUTPUT "Grade: A"
    ELSE
        OUTPUT "Grade: B or lower"
    ENDIF
ENDIF

3. The CASE OF Statement

If you have many different specific values to check, nested IF statements become very messy. The CASE OF statement is a much cleaner way to handle multiple choices. Always include an OTHERWISE clause to catch invalid data!

CASE OF Syntax
DECLARE MenuChoice : INTEGER
OUTPUT "Enter 1 to Play, 2 to Load, 3 to Quit:"
INPUT MenuChoice

CASE OF MenuChoice
    1 : OUTPUT "Starting new game..."
    2 : OUTPUT "Loading save file..."
    3 : OUTPUT "Exiting game..."
    OTHERWISE OUTPUT "Invalid choice."
ENDCASE

Common Syllabus Mistakes

When executing conditionals, watch out for these easily avoidable errors that cost students marks:

❌ Using "==" instead of "=": In Python, you use `==` to check if two values are equal. In standard Cambridge Pseudocode, you strictly use a single `=` sign (e.g., IF X = 10 THEN). Our compiler's Pro Mode will automatically flag `==` as a warning.

❌ Forgetting ENDIF: Unlike Python which uses indentation to know when a statement ends, Pseudocode requires the explicit ENDIF keyword. If you nest 3 IF statements, you must have 3 ENDIF statements at the end.

Interactive Exam Practice

Scenario: Write an algorithm that takes a student's mark (out of 100) as an input. If the mark is 50 or above, output the word "Pass". Otherwise, output "Fail".

Hover or tap the black box to reveal the examiner's solution. Click Run Code to test it instantly!

Tap to Reveal Answer
DECLARE Mark : INTEGER

OUTPUT "Enter student mark:"
INPUT Mark

IF Mark >= 50 THEN
    OUTPUT "Pass"
ELSE
    OUTPUT "Fail"
ENDIF

Previous Topic

← Guide 1: Variables

Next Topic

Guide 3: Loops ➔