basic.loop

Statement/BASIC Program, Releases: AP and R83

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

Command Name Type Description
basic.statements Definition Definition of statements and functions.
basic.until Statement Part of 'loop' and 'for ... next' constructs.
basic.search.for.truth Definition Evaluation of null and zero.
basic.relational.operators Relational Operator Returns the relationship between two expressions.
basic.for.next Statement Incremental loop function.
basic.repeat Statement see 'loop'.
basic.exit Statement Forces early exit from 'loop' or 'for ... next' construct.
basic.loop.until Statement Loops 'until' condition is met.
active.list Definition A list of strings delimited by attribute marks created by one of the list-generating processes.
basic.readnext Statement Retrieves the next item-id from an active list.
basic.do Statement Part of 'loop' construct.
basic.while Statement Part of 'loop' and 'for ... next'.
branching Definition

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.