Examples of FOR Statements

The following example executes the statement following DO just once, with I assigned zero.

FOR I:= 0 DO

The following example assigns 1 to elements 0 through 255 of array LOOKEDFOR.

FOR J:= 0 STEP 1 UNTIL 255 DO
   LOOKEDFOR[J]:= 1

The following example assigns ITEM to elements 0, 1, 2, 5, 10, 15, 16, and 37 of array BUF.

FOR INDEX:= 0, 1, 2, 10, 15, 37, 5, 16 DO
   BUF[INDEX]:= ITEM

The following example calls FETCH repeatedly, passing the values 0, 1, 2, 3, 4, 5, 29, and the values of (47 + 3 * X) where X = 0, 1, 2, and so on, as long as (47 + 3 * X) is less than LIM.

FOR X := 0 STEP 1 UNTIL 5, 29, 47 STEP 3 UNTIL LIM DO
   FETCH(X)

The following example calls PANHANDLE and assigns to NEXT values equal to BEG, BEG + AMT, BEG + 2*AMT, and so on, as long as DONE is FALSE.

FOR NEXT := BEG STEP AMT WHILE NOT DONE DO
   PANHANDLE

The following example increments TARGET by the value IX + 7 as long as TARGET is less than or equal to RANGE.

FOR N := IX + 7 WHILE TARGET LEQ RANGE DO
   TARGET := * + N