Re-cap and re-group
That pretty much covers the basics of state diagrams. A state diagram lets you
design the logic of a Finite State Machine (FSM). FSMs are an excellent tool
for desiging programs that must respond to external events in a way that depends on past history (the context).
The key elements of a state diagram are:
- The circle represents a place where the program is waiting for an event.
While it waits the outputs are unchanging. We call this a state.
- There can be more than one event being waited for in a state
- When an event takes place the state machine exits the state and transitions to a new state.
(It can actually transition to the same state, repeating any entry actions
)
- During the transition to a new state certain actions may be performed.
These actions are the useful output of the FSM.

- States can have timeouts that "fire" if none of the expected events occur within a set time limit.
Next, I will show you how a Finite State Machine can be coded in a couple of languages.
This style of FSM, where actions take place during state transitions,
is not the only possible one. This style is called a Moore state machine.
An alternative style is called a Mealy state machine. In a Mealy machine
the outputs are produced as a function of the state rather than as a
product of the state transitions. The difference, and the ramifications,
are rather subtle. Suffice to say that there are ways of converting one
type to the other type.
An Entry Action is an action that is always performed when
entering its associated state. An example of this is starting a timer
for use in a time-out.