6. Selection
Docs / Pseudocode / Selection
CAIE 0478 & 9618 Selection

6. Selection (IF & CASE OF)

Cambridge pseudocode conditional statements: IF..THEN..ELSE..ENDIF and CASE OF..OTHERWISE..ENDCASE with continuous value ranges.

Conditional logic in Cambridge pseudocode uses IF..THEN..ELSE..ENDIF or CASE OF..OTHERWISE..ENDCASE. CASE values may include discrete constants or continuous value ranges using TO.

IF .. THEN .. ELSE .. ENDIF

PSEUDOCODE
IF ChallengerScore > ChampionScore THEN
   IF ChallengerScore > HighestScore THEN
      OUTPUT ChallengerName, " is champion and highest scorer"
   ELSE
      OUTPUT ChallengerName, " is the new champion"
   ENDIF
ELSE
   OUTPUT ChampionName, " is still the champion"
   IF ChampionScore > HighestScore THEN
      OUTPUT ChampionName, " is also the highest scorer"
   ENDIF
ENDIF

CASE OF .. OTHERWISE .. ENDCASE

PSEUDOCODE
INPUT Move
CASE OF Move
   'W' : Position <- Position - 10
   'S' : Position <- Position + 10
   'A' : Position <- Position - 1
   'D' : Position <- Position + 1
   OTHERWISE : CALL Beep
ENDCASE

// CASE with range values
CASE OF Score
   90 TO 100 : Grade <- "A*"
   80 TO 89  : Grade <- "A"
   70 TO 79  : Grade <- "B"
   OTHERWISE : Grade <- "C or below"
ENDCASE