MATLAB: Do the during and on event statements in Stateflow form a nested if statement in generated code

stateflow

My stateflow state has the following code in it that includes a during statement as well as a an on event statement that is controlled by an after() operator.
When i generate code from this chart, i have a nested if statement with my during and on event statements nested inside each other. Why does this produce a nested if statement in the generated code?
My Stateflow actions:
du:
on after(300, msec): out = false;
if (Input > 0)
out = true;
end
The generated code:
if (temp_test_DW.temporalCounter_i1 >= 150U) {
/* '<S1>:1:2' out = false; */
temp_test_DW.out = false;
/* '<S1>:1:3' if (Input > 0) */
if (temp_test_B.Step > 0.0) {
/* '<S1>:1:4' out = true; */
temp_test_DW.out = true;
}
}

Best Answer

This code is actually correct for these state actions. As written, the during command is actually empty, and the if statement is contained inside the on after() even statement. for the if statement to be outside a nested if in the generated code, it must be moved to the during statement like this:
on after(300, msec): HoldSpont = false;
du:
if (Input > 0)
HoldSpont = true;
end
In this configuration, the during statement could set the output to true before the 300ms has elapsed. The alternative way to write this would have the during first:
du:
if (Input > 0)
HoldSpont = true;
end
on after(300, msec): HoldSpont = false;
However, this will output false after 300ms regardless of the Input value, as the on after() statement is execute after the during statement and overwrites the output value.
While all three of these look very similar, their end behavior is very different, as the state commands are evaluated in the order they appear.