FOR-UNTIL-DO

Repeatedly execute a statement (alternate)

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
FOR var = initial[ STEP incr] UNTIL final DO statement

var

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

initial

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

incr

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

final

An expression for the terminating value, which is compared against the current value of var at the beginning of each repetition of the statement. (n)

statement

A single or compound statement to be repeatedly executed.

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

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

Incr and final are evaluated prior to each execution of statement.

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

The difference between FOR-UNTIL-DO and FOR-FROM-THRU is that FOR-UNTIL-DO can modify the final and incr values, while FOR-FROM-THRU cannot.

Note

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

The following example assigns the values 65, 72, 79, and 86 to the elements of result. The first value is the initial value 65. Each of the remaining values is equal to the immediately preceding value plus 7. Only four values are assigned because v4 is assigned a value of 93 (86 + 7), which is greater than the final value of 91 before the fifth repetition.

record
    v1          ,d3, 13
    v2          ,d3, 5
    v3          ,d3, 7
    v4          ,d3
    i           ,d3, 1
    result      ,d4
proc
    for v4 = v1 * v2 step v3 until v1 * v3 do
      begin
        result(i) = v4
        incr i
      end
end

The following example assigns the values 20.2, 13.8, 7.4, and 1.0 to the first four elements of result.

record
    idval       ,d3.1
    i           ,d2,    1
    idresult    ,10d3.1
proc
    for idval = 20.2 step -6.4 until 0.0 do
      begin
        idresult(i) = idval
        incr i
      end
end