A switch statement
Listing 4 shows the beginning of a switch statement.
It uses the current value of the direction variable named dir:
(I gave you the correlation between the value of dir and the direction of motion earlier.)
Each case in the switch statement handles one of the four possible current values of dir.