basic.loop
Conditional loop function.
Syntax
loop {statement1{s}} [until | while] logical.expression do {statement2{s}} repeat loop {statement1{s}} [until | while] logical.expression do {statement2{s}} repeat loop {statement{s}} repeat
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.
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).
See Also
User Comments
What do you think?
Share your experience or ask a question by using the form below.
Login to leave your comments.
