FOR-FROM-THRU

Repeatedly execute a statement

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
FOR var FROM initial THRU final[ BY incr] statement

var

A variable that controls the repeated execution of the statement. (n)

initial

An expression whose value is initially assigned to var. (n)

final

An expression for the terminating value, which is compared against the current value of var. (n)

incr

(optional) An expression whose result is added to var after each repetition of the statement. The default value is 1. (n)

statement

A single or compound statement to be repeatedly executed.

The FOR-FROM-THRU statement executes a statement repeatedly as long as the control value is within a specified range.

If incr is positive, statement is executed while var is less than or equal to final. If incr is negative, statement is executed while var is greater than or equal to final.

Each time statement is executed, incr is added to var. If initial does not match the loop conditions, statement won’t be executed.

Incr and final are evaluated only once upon entry of the FOR-FROM-THRU statement, and then they are treated as constants during the rest of FOR statement processing.

Var, initial, incr, and final must all be the same data type.

Statement must execute code; for example, it cannot contain only a label.

The difference between FOR-FROM-THRU and FOR-UNTIL-DO is that you cannot modify the final and incr values with FOR-FROM-THRU. FOR-UNTIL-DO, on the other hand, can modify these values.

The following example assigns the values 3, 6, 9, 12, 15, 18, 21, and so forth, through 99, to the first 33 elements of result.

record
    i           ,d4,    1
    d1          ,d4,    3
    result      ,100d4
proc
    for d1 from 3 thru 100 by d1
      begin
        result(i) = d1
        incr i
      end
end