next up previous contents index
Next: 5.5.5 Break and Continue Up: 5.5 Mapping from Programming Previous: 5.5.3 Conditional Statements   Contents   Index

5.5.4 Loops

There are several kinds of loops in the C language:

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:

$init$;
loop_label:
if ($cond$) {
$stm$;
$step$;
goto loop_label;
}


Suppose $v$ 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.

$init$;
loop_label:
$v$ = $cond$; // evaluate $cond$ and store the result in $v$
if ($v$) {
$stm$;
$step$;
}
if ($v$)
goto loop_label;


Figure 5.5: An example of the transformation from a for-loop into multiple transitions
Image forloop2comp

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.


next up previous contents index
Next: 5.5.5 Break and Continue Up: 5.5 Mapping from Programming Previous: 5.5.3 Conditional Statements   Contents   Index
Thomas Huining Feng 2004-04-28