To keep track of every state and interaction in your program, design a state diagram of your state machine before you start programming.
A state diagram is an illustration of all the states in a state machine and how these states interact with each other. Each circle represents a state, and each arrow represents a possible state transition. While you create your code, you can follow the diagram flowchart to recall how to structure the state machine and how the states within the machine interact.
The following image shows an example of a basic state diagram for a program that changes the temperature of a room over time.
The state diagram shows all possible state transitions in the program. You can use the state diagram to understand how the states within the program interact before analyzing the code that defines the interactions.