---------- a3lo Loops ---------- 1 double CompoundInterest | 2 (double Principal, | 3 double Interest, | 4 int Years) | 5 |CompoundInterest 6 | (double Principal, 7 | double Interest, 8 | int Years) 9 { | 10 |{ 11 double Value; | 12 | double Value; 13 | double D.1594; 14 for (Value = Principal; | 15 Years > 0; |: 16 --Years) { | Value = Principal; 17 Value = Value * Interest; | goto ; 18 } | 19 |: 20 | Value = Value * Interest; 21 | Years = Years - 1; 22 | 23 |: 24 | if (Years > 0) 25 | goto ; 26 | else 27 | goto ; 28 | 29 return Value; | 30 |: 31 | D.1594 = Value; 32 | return D.1594; 33 } | 34 |} 1 A for-loop is translated in terms of (a) An initialization part which is separated out. (b) A forward jump to the loop condition situated at the bottom of the loop. If the loop should continue this condition makes a backward jump to the loop body. (c) The increment part of the for-loop is added at the end of the loop body just before the condition. Observe that the above transformation actually converts a for-loop into a do-while loop; the potentially-zero-iteration path of a for-loop is supported by a jump to the condition from outside of the loop. 2 There is no difference between translation of a for-loop and a while-loop.