Chapter
10
I
BASIC
Ke.ywords
WHILE
...
WEND
Statement
WHILE
expression
WEND
Executes a series of statements in a loop as long as a given con-
dition is true.
Expression
is any numeric
or
string expression, usually making
logical
or
relational comparisons.
If
expression
is true, BASIC executes the statements after the
WHILE statement until it encounters
a
WEND statement. Then
BASIC returns
to
the WHILE statement and checks
expression.
If it is still true, BASIC repeats the process. If it is not true, exe-
cution resumes with the statement following the WEND
statement.
You may nest WHILE/WEND loops to any level. Each WEND
matches the most recent WHILE. An unmatched WHILE state-
ment causes
a
“WHILE without WEND” error, and an un-
matched WEND causes
a
“WEND without WHILE” error.
Sample Program
90 “BUBBLE SORT ARRAY
A$
100 FLIPS=l “FORCE ONE PASS THRU LOOP
11
0 WHILE FLIPS
115 FLIPS=0
120 FOR
I=l
TO
J-1
130 IF A$(I)>A$(I+l)THEN SWAP
A$<I),
140 NEXT
I
150 WEND
A$(I+1
1:
FLIPS=l
This program sorts the elements in
array
A$. Control
falls
out
of
the WHILE loop when no more swaps are performed on Line
130.
341