|
10.2.7 UnswitchingLOOP FOR I := 1 TO 1000 IF (Test) THEN X (I) := A(I) + B(I) ELSE X(I) := A(I) - B(I) ENDLOOP Here, the test is performed each time through the loop. The following performs the test once: IF (Test) THEN LOOP FOR I := 1 to 1000 X(I) = A(I) + B(I) ENDLOOP ELSE LOOP FOR I := 1 to 100 X(I) = A(I) - B(I) ENDLOOP The second version here reduces the number of instructions executed,
but the code takes more space. |