When there is a valid transition out of a state, that state is marked for exit. A state is marked for exit in one of these ways:
The outgoing transition originates at the state boundary.
The outgoing transition crosses the state boundary.
The destination state is a parallel state child of an activated state.
This flow chart shows the progression of events in Stateflow® for exiting a state. In this flow chart, the current state refers to the state in which a decision or a process is taking place.
Exit
actions for a state execute when the state is active and a
valid transition from the state exists. A state performs its exit
actions before becoming inactive.
Exit actions are preceded by the prefix exit
or
ex
, followed by a required colon (:
), and then
followed by one or more actions. Separate multiple actions with a carriage return,
semicolon (;
), or a comma (,
).
In this example, the Stateflow chart is initialized and the entry
actions are
performed for StateA
and StateA1
. For this chart,
the during
actions for this chart have occurred twice. A new time
step occurs, and then the chart wakes up.
By following the Workflow for Stateflow Chart Execution and the Workflow for Evaluating Transitions,
StateB
has been marked for entry. StateA
is the
source of the transition. At this time step x = 5
, y =
2
, and z = 0
.
By following the flow chart for state exit actions until the chart goes to sleep, the execution steps for this chart are in this order:
StateA
is not a superstate of
StateB
.
Perform the exit actions of StateA
and mark
StateA
as inactive. Now z = 1
.
StateA
does not have a parent state.
Go to Entry Actions.
These steps complete the exit
workflow for
StateA
. However, the chart is not yet asleep.
Perform the Workflow for Entering a Chart or State for
StateB
to complete the time step.
A supertransition is a transition between different levels in a chart. A supertransition can be between a state in a top-level chart and a state in one of its substates, or between states residing in different substates. You can create supertransitions that span any number of levels in your chart.
When a state is exited through a supertransition, after the exit actions for the
source of the transition are executed, its superstates are marked inactive and exit
actions of the superstates are executed. In this example, StateA2
is
marked for exit
and StateB1
is marked for
entry
. At this point, x = 5
, y =
5
, and z = 0
.
By following the Workflow for Entering a Chart or State until the chart
goes to sleep, the execution steps for exiting the state StateA2
are
in this order:
StateA2
is not a superstate of the destination state
(StateB1
).
Perform the exit
actions for StateA2
and
mark StateA2
as inactive.
StateA2
does have a parent state,
StateA
.
StateA
is not a superstate of the destination state
(StateB1
).
Perform the exit
actions for StateA
, and
mark StateA
as inactive.
StateA
does not have a parent state.
These actions complete the exit
workflow for
StateA2
and StateA
. However, the chart is not
yet asleep.
Perform the Workflow for Entering a Chart or State for
StateB
and StateB1
to complete the time
step.