# LOOP

Updated: 11/30/2021, 7:00:45 PM
Created: 11/30/2021, 7:00:45 PM
Last Updated By: Jake Tuttle
Read Time: 1 minute(s)

Tags: until loop loop until until loop while while loop loop while program execution control structures

# Description

The LOOP construct allows the programmer to specify loops with multiple exit conditions. The construct takes the general form:

LOOP statements1 WHILE|UNTIL expression DO statements2 REPEAT
1

Where:

  • statements1 and statements2 consist of any number of standard statements including  the LOOP statement itself, thus allowing for nested loops. statements1 will always be executed at least once, after which the WHILE or UNTIL clause is evaluated.
  • expression is tested for Boolean TRUE/FALSE by either the WHILE clause or the UNTIL clause.

When tested by the WHILE clause statements2 will only be executed if expression is Boolean TRUE. When tested by the UNTIL clause, statements2 will only be executed if the expression evaluates to Boolean FALSE. .

REPEAT causes the loop to start again with the first statement following the LOOP statement. An example of use is as:

loop
    input answer,1 until NUM(answer)
repeat
1
2
3

to keep asking for an input until the user enters a numeric value.

See also: BREAK, CONTINUE

Go back to jBASE BASIC

Go back to Programmers' Reference Guide