Skip to content

WHILE/WEND

Loop Controlled by Conditional Test

This directive provides a loop within a program, which is defined by the WHILE directive and terminated by the WEND directive.

WHILE condition
WEND
condition
is a relational, Boolean, and/or logical expression used to establish a true or false condition.

This directive is generally available starting with release level 8.1.

The syntax for the condition is:

num/str-value relational-operator num/str-value
[[logical-operator num/str-value relational-operator num/str-value]…]
or
numeric-value

num/str-value
is any valid numeric or string expression.
relational-operator
is any of the valid comparison operators listed below.
logical-operator
is any of the valid logic operators listed below.
numeric-value
is any valid numeric expression. If numeric-value is zero, the condition is false; if other than zero, true.
relational-operator meaning
= equal to
<> or >< not equal to
> greater than
< less than
>= or => greater than or equal to
<= or =< less than or equal to
=ALL (string-value) =ALL function
LIKE string-value partial equality
logical-operator meaning
OR logical OR of multiple conditionals
AND logical AND of multiple conditionals
( ) group multiple conditionals into specific priority order

The LIKE operator can specify a string value containing wildcards, which can match more than 1 character. LIKE automatically pads its values to the correct length.

LIKE wildcards meaning
“*” matches any string of characters (0 or more)
“?” matches a single character
“[A-Z]” matches a range for a single character
“[AGCF]” matches a single character in a list
“[wildcard]” matches the specified wildcard character

WHILE/WEND directives may be nested or strung together to form complex looping operations.

If a WHILE is executed without a matching WEND, an ERR=28 results.

WHILE/WEND can be used in Thoroughbred Basic Run Mode only. If an attempt is made to execute a WHILE/WEND directive in Thoroughbred Basic Console Mode, an ERR=45 results.

If the condition is initially false the entire WHILE/WEND program loop is bypassed. If initially true, then the loop executes until the condition becomes false and program control resumes after the matching WEND directive.

The normal exit from a WHILE/WEND is to satisfy the stated condition. An abnormal exit requires the removal of a scheduled place-to-go on the stack with the EXITTO directive.

Each WHILE directive is terminated by the WEND directive. Although the WEND directive need not physically reside at a higher program line number or label than its associated WHILE directive, an error could result when the initial test of condition indicates that the loop should not be taken. Thoroughbred Basic then searches forward in program line order for the matching WEND directive. If a matching WEND is not found, an ERR=28 results. If the programmer does not place the corresponding WEND after (at a higher program line) the matching WHILE, it is probable that an unmatched WHILE/WEND condition is reported and an ERR=28 results.

01000 LET KEY_TEST_VALUE$ = "TOPKEY"
01010 WHILE KEY_VALUE$ < KEY_TEST_VALUE$
01020 LET KEY_VALUE$ = KEY(1);
READ RECORD (1, KEY = KEY_VALUE$) RECORD$;
PRINT (2) RECORD$
01030 WEND

READs the DIRECT file OPEN on channel 1 and PRINTs each record out on channel 2 until the key value of the DIRECT file on channel 1 is no longer less than the value “TOPKEY”.

FOR/NEXT directive

From the Thoroughbred Basic Language Reference, Volume III: R–Z, version 8.9.1. Open this page in the PDF