Repeatedly execute a statement

WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
FOR var FROM initial THRU final[ BY incr] statement



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


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


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


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


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.

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