Designers may optionally specify guards (boolean conditions) for transitions and enter/exit actions. The guard of a transition is tested when the event of the transition is received. The transition is triggered only if the result of this testing is true. Similarly, when the model enters or exits a state and if corresponding enter/exit actions are defined, they are executed only if the guards are evaluated to true.
The following example (guard1.des) demonstrates the use of guards:
STATECHART: A [DS] A1 [DS] A2 A3 B ENTER: N: A C: 1==1 O: [DUMP("enter A")] EXIT: S: A C: 1==0 O: [DUMP("exit A")] TRANSITION: S: A N: B E: e C: [INSTATE("A.A1")] or [INSTATE("A.A2")] O: [DUMP("transition to B")]
The result of the simulation is:
enter A ['A.A1'] > e transition to B ['B'] > exit
When state A is entered initially, the guard (1==1) of its enter action is tested. Since the result is true, the action is executed and ``enter A'' is printed. When the transition is triggered, its guard is tested. Predefined macro INSTATE is used to test whether the model is in state A.A1 of A.A2. The result is true, so the output of the transition is also executed. The exit action of state A is not executed because its guard is evaluated to false.