External Exam Download Resources Web Applications Games Recycle Bin

Selection

Selection can be used to make branching decisions to the next instruction to be processed, based on a condition (i.e., a logical expression that evaluates to true or false):

BEGIN trafficLights
  INPUT lightColour
  IF lightColour == "green" THEN
    DISPLAY "Go"
  ELSE
    IF lightColour == "red" THEN
      DISPLAY "Stop"
    ELSE
      DISPLAY "Wait"
    ENDIF
  ENDIF
END trafficLights

Python uses indentation to mark blocks of code, which is why you don't see endif in Python:

trafficLights.py

#BEGIN trafficLights

lightColour = input("lightColour: ") #INPUT lightColour
if lightColour == "green": #IF lightColour == "green" THEN
  print("Go") #DISPLAY "Go"
else: #ELSE:
  if lightColour == "red": #IF lightColour == "red" THEN
    print("Stop") #DISPLAY "Stop"
  else: #ELSE:
    print("Wait") #DISPLAY "Wait"
  #ENDIF
#ENDIF

#END trafficLights