The break statement and the continue statement in a loop can be transformed into extra transitions.
Suppose statement comp_stm is such a compound statement:
;
loop_label:
if () {
;
if (finished)
break;
;
;
goto loop_label;
}
The break statement stops the for-loop by changing the execution
point out of the compound statement. It is equivalent to:
;
loop_label1:
= ; // evaluate and store the result in
if () {
;
if (finished)
goto loop_label2;
;
;
}
if ()
goto loop_label1;
loop_label2:
The transformation of the model is illustrated in Figure 5.6. The break statement in the for-loop is eliminated in this example.
The continue statement in a loop can be eliminated in a similar
way. If the break statement in the above comp_stm is
replaced by the continue statement, it is equivalent to:
;
loop_label:
= ; // evaluate and store the result in
if () {
;
if (finished)
goto loop_label;
;
;
}
if ()
goto loop_label;
The transformation of this code with the continue statement is shown in Figure 5.7.