FOR-DO

Repeatedly execute a statement

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
FOR variable = value[, ...] DO statement

variable

A variable that is modified before each execution of the loop. (a or n)

value

An expression to be assigned to variable before each execution of statement. All values must be the same data type as variable. (a or n)

statement

A single or compound statement to be repeatedly executed.

The FOR-DO statement executes a statement repeatedly until a specified list of values is evaluated.

The first value in the list is assigned to variable before the first execution of the statement, the second value is assigned before the second execution, and so forth. When each value in the list has been assigned, the FOR statement is terminated and control is transferred to the statement following the FOR statement.

Statement can be on the next physical line. It is executed once for each value specified. Statement must execute code; for example, it cannot contain only a label.

Note

The FOR and the DO keywords must always be on the same line.

The following example assigns the values 8, 28, 13, 33, and 38 to result elements 1, 5, 2, 6, and 7, respectively.

record
    v1          ,i2
    v2          ,i2
    i           ,i2
proc
    v1 = 3
    v2 = 5
    for i = 1, 5, 2, 6, 7 do
      result(i) = v2 * i + v1
end

The following example assigns four separate alpha values to a complex manipulation.

record
    string      ,a100
    alf         ,50a10
    len         ,i2
    maxlen      ,i2
    result      ,a200
proc
    for string = alf(12), alf(17), alf(22), alf(35) do
      begin
        xcall cnvrt(string, len)
        if (len .gt. maxlen)
          string(maxlen + 1) = '%'
        xcall parse(string, result)
        xcall act(result)
      end
end