There are several kinds of loops in the C language:
For-loops can be transformed into statements with an if-else
condition. The above for-loop structure is transformed into:
;
loop_label:
if () {
;
;
goto loop_label;
}
Since other types of loops can be simulated with for-loops, it is
enough to show that for-loops can be modeled with DCharts. As shown
above, for-loop can be transformed into:
;
loop_label:
if () {
;
;
goto loop_label;
}
Suppose is a temporary boolean variable. This code is equivalent
to the following piece of code (denote it with comp_stm). It
brings the ``goto'' statement out of the conditional construct.
;
loop_label:
= ; // evaluate and store the result in
if () {
;
;
}
if ()
goto loop_label;
A model with a transition from state A to B that has the above action code in the output (the upper part of Figure 5.5) is transformed into the model in the lower part of Figure 5.5. If compound statements are still found in the output of the generated transitions, further transform the model into valid DCharts models with the method in previous sections.
This proves that all kinds of loops can be modeled with DCharts.
This transformation does not take into account synchronization among actions in different orthogonal components either.