A Switch Statement State Machine
This is one of the easiest state machines to implement, and is one of the first that programmers will encounter, most often by intuitive happenstance.
The code below demonstrates the switch() state machine with a basic motor-based example:
You can add code which runs only on the entry to each state by keeping track of the previous state. You will now see why I added the MotorStates::NONE state.
One of the drawbacks is that you have to remember to break out of every case, otherwise you will get fall through to the next state.