Stateflow |
 |
Entering a State
A state is entered (becomes active) in one of the following ways:
- Its boundaries are crossed by an incoming executed transition.
- Its boundary terminates the arrow end of an incoming transition.
- It is the parallel state child of an activated state.
A state performs its entry
action (if specified) when it becomes active. The state is marked active before its entry
action is executed and completed.
The execution steps for entering a state are as follows:
- If the parent of the state is not active, perform steps 1 through 4 for the parent first.
- If this is a parallel state, check to make sure that all sibling parallel states with a higher execution order are active. If not, perform all entry steps for these states first in the appropriate order of entry.
- Parallel (AND) states are ordered for entry based on their vertical top-to-bottom position in the diagram editor. Parallel states that occupy the same vertical level are ordered for entry from left to right. In the following example, parallel states
A
and B
are aligned at the same vertical level while states A
and C
and states B
and D
are aligned at the same horizontal position. Based on their top-down positions in the diagram editor, the order of execution for these states is A
or B
, then D
and C
. Because A
is left of B
, A
is evaluated first and the order of entry is A
, B
, D
, C
.

- Mark the state active.
- Perform any entry actions.
- Enter children, if needed:
- Execute the default flow paths for the state unless it contains a history
junction.
- If the state contains a history junction and there is an active child of this
state at some point after the most recent chart initialization, perform the
entry actions for that child.
- If this state has children that are parallel states (parallel decomposition),
perform entry steps 1 to 5 for each state according to its entry order.
- If this is a parallel state, perform all entry actions for the sibling state next in entry order if one exists.
- If the transition path parent is not the same as the parent of the current state, perform entry steps 6 and 7 for the immediate parent of this state.
- The chart goes to sleep.
| Executing a State | | Executing an Active State |  |