Skip to content

Lesson 31: State machine

One state at a time

  • Many machines are always in one state: a turnstile is LOCKED or UNLOCKED, a washing machine is filling, washing or spinning.
  • An input (a coin, a push) can move the machine to another state. The same input can do different things in different states.
  • A program like this is a state machine. In C++ it is a switch with one case for each state.

Words for this lesson

Word Meaning
state what the machine is doing now
transition a change from one state to another
turnstile a gate that lets one person through at a time
switch / case choose the code for the value of a variable

Log in or create account

IGCSE, A-Level & AP