A state machine consists of discrete segments of code, otherwise known as states, that execute one at a time with a transition between each execution.
The following tasks are examples of situations for which state machines are well suited:
However, a state machine is not well suited for every programming situation. If your program needs to run parallel processes, you may want to choose a different design pattern.