| Contents | Index |
| On this page… |
|---|
You can combine entry, during, and exit actions that execute the same tasks in a state.
By combining state actions that execute the same tasks, you eliminate redundant code. For example:
| Separate Actions | Equivalent Combined Actions |
|---|---|
entry: y = 0; y++; during: y++; | entry: y = 0; entry, during: y++; |
en: fcn1(); fcn2(); du: fcn1(); ex: fcn1(); | en, du, ex: fcn1(); en: fcn2(); |
Combining state actions this way produces the same chart execution behavior (semantics) and generates the same code as the equivalent separate actions.
Combine a set of entry, during, and/or exit actions that perform the same task as a comma-separated list in a state. Here is the syntax:
entry, during, exit: task1; task2;...taskN;
You can also use the equivalent abbreviations:
en, du, ex: task1; task2;...taskN;
You can use any combination of the three actions. For example, the following combinations are valid:
en, du:
en, ex:
du, ex:
en, du, ex:
You can combine actions in any order in the comma-separated list. For example, en, du: gives the same result as du, en:. See Order of Execution of Combined Actions.
You cannot combine two or more actions of the same type. For example, the following combinations are invalid:
en, en:
ex, en, ex:
du, du, ex:
If you combine multiple actions of the same type, you receive a warning that the chart executes the action only once.
States execute combined actions in the same order as they execute separate actions:
Entry actions first, from top to bottom in the order they appear in the state
During actions second, from top to bottom
Exit actions last, from top to bottom
The order in which you combine actions does not affect state execution behavior. For example:
| This state... | Executes actions in this order... |
|---|---|
|
|
|
|
|
|
|
|
Do not combine multiple actions of the same type.
Do not create data or events that have the same name as the action keywords: entry, en, during, du, exit, ex.
![]() | Supported Action Types for States and Transitions | Supported Operations on Chart Data | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |