Page 27 of 62
SBasic User's Manual SBasic Version 2.7 Page 27
Printed: December 5, 1999
Control structures
SBasic supports several structures for controlling the flow of your
program. Used properly, these control structures can improve the
quality of your program design, making your source file easier to
read, understand, and debug.
Some of the following control structures allow or require a comparison
clause. Such clauses consist of an expression, a comparison operator,
and a second expression. The comparison clause is evaluated as your
program runs and, depending on the evaluation, control transfers
within the control structure.
Example:
while a < 5
a = a + 1
wend
Here, the comparison clause "a < 5" determines whether control remains
in the WHILE-WEND loop or transfers to the line following the WEND
statement.
All comparison clauses may contain one and only one comparison
operator. Multiple comparisons, such as:
while a < 5 and c-1 = 3
are illegal and will generate compilation errors.
Note also that you do not enclose comparisons within parentheses.
Doing so will result in a compilation error.
WHILE-WEND is a conditional loop structure. Control executes all
statements between the WHILE statement and the WEND statement for so
long as the comparison in the WHILE clause is TRUE. When the
comparison becomes FALSE, control exits the loop by transferring to
the line following the WEND statement.
Example:
while a < 500 ' loop while a is less than 500
a = a + 1 ' increment a
wend ' end of loop
This example loops for so long as the value in A is less than
(unsigned) 500.
Note that WHILE-WEND is obsolete, even though SB still supports it.
WHILE-WEND has been replaced by the more flexible DO-LOOP structure.
DO-LOOP is a loop structure that may be either conditional or
unconditional. Control executes all statements between the DO