| logical expressions | Index Level | LOOP ... UNTIL |
| Syntax |
LOOP {statement1{s}} [UNTIL | WHILE] logical.expression DO {statement2{s}} REPEAT
-or- LOOP {statement1{s}} [UNTIL | WHILE] logical.expression DO {statement2{s}} REPEAT -or- LOOP {statement{s}} REPEAT |
| Category | BASIC |
| Type | Statement |
| Description |
repetitively executes (loops) until some ending condition is met. The first set of statements, if present, is executed at least once.
The "loop..until" or "loop..while" forms are repetitive loop functions used to repeat a sequence of statements conditionally. If the "until" clause is used, looping continues as long as the expression following it is false. If the "while" clause is used, looping continues as long as the expression following it is true. The statements in the "do" clause are executed as long as the loop is executed. If "while" or "until" is specified, the "do" is required. The "repeat" statement defines the end of the loop. If neither a "while" nor "until" clause is used, the loop never finishes. The use of "goto" or "exit" is required to exit the loop in this construct. If the "until" expression is initially true or the "while" expression is initially false, the statements specified in "statements1" are executed at least once and "statements2" are not executed. |
| Options | |
| See Also | statements & functions UNTIL Boolean Evaluation relational operators FOR ... NEXT REPEAT EXIT LOOP ... UNTIL active list READNEXT DO WHILE branching |
| Example |
loop
crt "enter value to test " : input value,1 until value = "q" do repeat This loop terminates when "value" evaluates to a "q". loop x = c*2 while x < 100 do c = c + 1 repeat This loop terminates when the calculated value of "x" is under 100. Each time through the loop, "c" is incremented by one. execute "select customers" loop readnext item.id else exit print item.id repeat This processes an active list. When the last item-id is read, the "exit" statement passes control to the next executable statement after the "repeat" statement. Notice the select list is the default active select list. (see readnext). |
| Warnings | |
| Compatibility | D3 7.0 AP R83 |
| logical expressions | Index Level | LOOP ... UNTIL |