ProvideX V8.20 > Language Reference > 2. Directives
373
WHILE..WEND Directive
          Repeat Statements
Format
WHILE expression
..WEND
Where:
expression Numeric expression. When the evaluated value of the expression is 0
(zero, false) looping ends.
WEND
Directive required to end the WHILE sequence.
Description
Use the WHILE directive for conditional looping in a program. ProvideX executes all
directives between a WHILE directive and the next WEND directive repeatedly until
the value of the expression is 0 zero.
When ProvideX encounters a WHILE directive, it evaluates the expression. If the
result is not 0 zero, ProvideX continues execution until a corresponding WEND
directive is encountered, at which point the expression is re-evaluated. ProvideX
continues to loop back to the directive following the WHILE directive until a 0 value
is reached. At this point, ProvideX advances to the next WEND directive, where it
terminates the loop. Then control transfers to the statement following the WEND.
The expression would normally include a logical operator (such as an equals =, less-than
symbol <, or the LIKE Operator, p.827), but you can use any numeric expression.
If ProvideX encounters a WEND directive but is not currently processing a WHILE /
WEND loop, it returns an Error #27: Unexpected or incorrect WEND,
RETURN, or NEXT. All FOR/NEXT, GOSUB/RETURN, and WHILE/WEND sequences
executed within the WHILE/WEND loop must be completed.
Use a conditional EXITTO or BREAK to exit a WHILE/WEND loop early.
See Also
BREAK Immediate Exit of Loop, p.33,
CONTINUE Initiates Next Iteration of Loop, p.56
EXITTO End Loop, Transfer Control, p.124
LIKE Operator, p.827
Loop Structures, User's Guide.
Example
0100
WHILE A$<>"E"
0110
LET K$=KEY(1,END=1000)
0120
READ (1)N$
0130
PRINT "Key: ",K$," Name: ",N$
0140
INPUT "Delete (Y/N):",A$
0150
IF A$="Y" THEN REMOVE (1,KEY=K$)
0160
WEND
0170
STOP
1000
PRINT "End-of-file..."
1010
EXITTO 0170