Eliminate Redundant Code by Combining State Actions
You can combine
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=y+1; during: y=y+1;
entry: y = 0; entry, during: y=y+1;
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.
How to Combine State Actions
Combine a set of
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:
You can combine actions in any order in the comma-separated list. For example,
en, du: gives the same result as
You cannot combine two or more actions of the same type. For example, the following combinations are invalid:
If you combine multiple actions of the same type, you receive a warning that the chart executes the action only once.
Order of Execution of Combined Actions
States execute combined actions in the same order as they execute separate actions:
Entryactions first, from top to bottom in the order they appear in the state
Duringactions second, from top to bottom
Exitactions last, from top to bottom
The order in which you combine actions does not affect state execution behavior. For example:
|Combined Actions||Order of Exectution|
Rules for Combining State Actions
Do not combine multiple actions of the same type.
Do not create data, events, or messages that have the same name as the action keywords: