Syllabus: Cambridge Pseudocode
1.1 Free

IF THEN ELSE

One or two outcomes.

The IF structure

IF condition THEN
    statements when TRUE
ELSE
    statements when FALSE
ENDIF

The ELSE part is optional.

Worked example: positive, negative or zero

INPUT n
IF n > 0 THEN
    OUTPUT "positive"
ELSE
    IF n < 0 THEN
        OUTPUT "negative"
    ELSE
        OUTPUT "zero"
    ENDIF
ENDIF

Common mistakes

  • Forgetting ENDIF.
  • Using = when you mean to compare. In Cambridge pseudocode both assignment and comparison are written carefully: assignment uses <-, comparison uses =.

Practice tasks

  1. 1Output "pass" if a mark is 40 or more.
  2. 2Output the largest of three numbers.