Table Of Contents

Standard States To Consider When Planning Your Program

Last Modified: February 27, 2020

When you design a state machine, create a distinct initialize state and shutdown state for the program. You can also add a specific state to handle user input or provide custom error handling, depending on your program needs.

States to Include in Every State Machine You Create

Specify one entry point and one exit point for a state machine to control the code that executes each time the state machine starts up and shuts down.

  • Initialize state—The first state a state machine executes, which includes any application initialization code. Common uses for initialization code include opening file references and hardware references to use later and bundling control references into the data cluster to unbundle later.
  • Exit state—The final state a state machine executes, which includes any code used during the shutdown process. Common uses for shutdown code include closing any open references to free memory, flushing any buffers in use, and writing safe values to hardware input channels.

A state machine runs continuously until the condition terminal on the While Loop receives the stop value determined by the user. Directing your state machine toward a single exit rather than accounting for multiple exit points allows you to control the shutdown code that executes each time the machine stops. Using a single exit state also helps prevent accidental, premature, or partial state machine shutdowns.

States to Consider Depending on Your Program Needs

If you are designing a program that implements user interface actions or contains specialized error handling, consider including these states in your state machine.

  • Wait for event state—A state that accepts and implements user input.
  • Error handling state—A state that contains error handling code for the state machine.

Recently Viewed Topics