Control Chart Execution by Using Condition Actions
Condition Action Behavior
This example shows the behavior of a simple condition action in a transition path with multiple segments.

Initially, the chart is asleep. State A is active. Conditions
C_one and C_two are false. Event
E_one occurs and awakens the chart, which processes the event
from the root down through the hierarchy:
The chart root checks to see if there is a valid transition as a result of
E_one. A valid transition segment from stateAto a connective junction is detected. The condition actionA_oneis detected on the valid transition segment and is immediately executed and completed. StateAis still active.Because the conditions on the transition segments to possible destinations are false, none of the complete transitions is valid.
State
Aduring actions (durA()) execute and complete.State
Aremains active.The chart goes back to sleep.
This sequence completes the execution of this Stateflow® chart associated with event E_one when state
A is initially active.
Condition and Transition Action Behavior
This example shows the behavior of a simple condition and transition action specified on a transition from one exclusive (OR) state to another.

Initially, the chart is asleep. State A is active. Condition
C_one is true. Event E_one occurs and
awakens the chart, which processes the event from the root down through the
hierarchy:
The chart root checks to see if there is a valid transition as a result of
E_one. A valid transition from stateAto stateBis detected. The conditionC_oneis true. The condition actionA_oneis detected on the valid transition and is immediately executed and completed. StateAis still active.State
Aexit actions (ExitA()) execute and complete.State
Ais marked inactive.The transition action
A_twois executed and completed.State
Bis marked active.State
Bentry actions (entB()) execute and complete.The chart goes back to sleep.
This sequence completes the execution of this Stateflow chart associated with event E_one when state
A is initially active.
Create Condition Actions Using a For-Loop
Condition actions and connective junctions are used to design a
for loop construct. This example shows the use of a condition
action and connective junction to create a for loop
construct.

See For-Loop Construct to see the behavior of this example.
Broadcast Events to Parallel (AND) States Using Condition Actions
This example shows how to use condition actions to broadcast events immediately to parallel (AND) states.

See Broadcast Events in Condition Actions to see the behavior of this example.
Tip
Avoid using undirected local event broadcasts. Undirected local event broadcasts can cause unwanted recursive behavior in your chart. Instead, send local events by using directed broadcasts. For more information, see Broadcast Local Events to Synchronize Parallel States.
During simulation, Stateflow charts can detect undirected local event broadcasts. To control the level of
diagnostic action, open the Configuration Parameters dialog box and, in the Diagnostics > Stateflow pane, set the Undirected event broadcasts parameter to
none, warning, or
error. The default setting is
warning. For more information, see Undirected event broadcasts (Simulink).
Avoid Cyclic Behavior
This example shows a notation to avoid when using event broadcasts as condition actions because the semantics results in cyclic behavior.

Initially, the chart is asleep. State On is active. Event
E_one occurs and awakens the chart, which processes the event
from the root down through the hierarchy:
The chart root checks to see if there is a valid transition as a result of
E_one.A valid transition from state
Onto stateOffis detected.The condition action on the transition broadcasts event
E_one.Event
E_oneis detected on the valid transition, which is immediately executed. StateOnis still active.The broadcast of event
E_oneawakens the chart a second time.Go to step 1.
Steps 1 through 5 continue to execute in a cyclical manner. The transition label
indicating a trigger on the same event as the condition action broadcast event
results in unrecoverable cyclic behavior. This sequence never completes when event
E_one is broadcast and state On is
active.
Tip
Avoid using undirected local event broadcasts. Undirected local event broadcasts can cause unwanted recursive behavior in your chart. Instead, send local events by using directed broadcasts. For more information, see Broadcast Local Events to Synchronize Parallel States.
During simulation, Stateflow charts can detect undirected local event broadcasts. To control the level of
diagnostic action, open the Configuration Parameters dialog box and, in the Diagnostics > Stateflow pane, set the Undirected event broadcasts parameter to
none, warning, or
error. The default setting is
warning. For more information, see Undirected event broadcasts (Simulink).