Stateflow User's Guide Previous page   Next Page

Entering a State

A state is entered (becomes active) in one of the following ways:

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:

  1. If the parent of the state is not active, perform steps 1 through 4 for the parent first.
  2. If this is a parallel state, check if a sibling parallel state previous in entry order is active. If so, start at step 1 for this parallel state.
  1. 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 entry for these states is A or B, then C, then D. Because A is left of B, A is evaluated first and the order of entry is A, B, D, C. Stateflow marks this order with an order number in the upper right-hand corner of the state (1, 2, 3, 4, respectively)

    Step 2 says that if you are entering state D in step 1, check if state B is active. If it is not, start at step 1 for state B. Step 2 repeats for state B and, if A is not active, start at step 1 for A. Since there are no parallel states of lesser entry order, continue with step 3 for state A.

  1. Mark the state active.
  2. Perform any entry actions.
  3. Enter children, if needed:
    1. Execute the default flow paths for the state unless it contains a history junction.
    2. 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.
    3. 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.
  4. If this is a parallel state, perform all entry steps for the sibling state next in entry order if one exists.
  5. 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.
  6. The chart goes to sleep.

Previous page  Entering, Executing, and Exiting a State Executing an Active State Next page

© 1994-2005 The MathWorks, Inc.