In this section: How to: |
The Dialogue Manager command -REPEAT allows looping in a procedure.
-REPEAT label {n TIMES [FROM fromval] [TO toval] [STEP s]} -REPEAT label {WHILE condition [FROM fromval] [TO toval] [STEP s]} -REPEAT label {FOR &variable [FROM fromval] [TO toval] [STEP s]}
where:
Identifies the code to be repeated (the loop). A label includes another loop if the label for the second loop has a different name from the first.
Specifies the number of times to execute the loop. The value of n is a local variable, a global variable, or a constant. If it is a variable, it is evaluated only once, so the only way to end the loop early is with -QUIT or -EXIT (the number of times to execute the loop cannot be changed).
Specifies the condition under which to execute the loop. The condition is any logical expression that is either true or false. The loop is run if the condition is true.
Is a variable that is tested at the start of each execution of the loop. It is compared with the value of fromval and toval (if supplied). The loop is executed only if &variable is less than or equal to toval (STEP is positive), or greater than or equal to toval (STEP is negative).
Is a constant that is compared with &variable at the start of each execution of the loop. 1 is the default value.
Is a value that is compared with &variable at the start of each execution of the loop. 1,000,000 is the default value.
Is a constant used to increment &variable at the end of each execution of the loop. It may be positive or negative. 1 is the default value.
The parameters FROM, TO, and STEP appear in any order.
A loop ends in one of three ways:
Note: If you later issue another -GOTO to return to the loop, the loop proceeds from the point where it left off.
This section illustrates how to write each of the syntactical elements of -REPEAT.
Example:
-REPEAT LAB1 2 TIMES -TYPE INSIDE -LAB1 TYPE OUTSIDE
The output is:
INSIDE INSIDE OUTSIDE
Example:
-SET &A = 1; -REPEAT LABEL WHILE &A LE 2; -TYPE &A -SET &A = &A + 1; -LABEL TYPE END: &A
The output is:
1 2 END: 3
Example:
-REPEAT LABEL FOR &A FROM 1 TO 4 STEP 2 -TYPE INSIDE &A -LABEL TYPE OUTSIDE &A
The output is:
INSIDE 1 INSIDE 3 OUTSIDE 5
iWay Software |