Previous Topic: FOR..NEXT..STEP StatementsNext Topic: REPEAT..UNTIL Statements


WHILE..WEND Statements

A WHILE..WEND statement contains an expression that controls the repetitive execution of a statement block.

The expression result must be of type Integer. The statement block is run repeatedly as long as the expression evaluates to true (nonzero). If the expression is false (zero) initially, the statement block is not run.

The statement syntax is as follows:

WHILE <expression>
<statement block>
WEND

EXIT WHILE exits the WHILE..WEND loop.

Example:

DIM FileName as String
DIM NoOfLines as Integer
DIM TmpLine as string
DIM hFile as Integer
FileName="C:\AUTOEXEC.BAT"
NoOfLines=0
hFile=OpenFile(FileName,0,0)
WHILE NOT(Eof(hFile))
  ReadFile(hFile,TmpLine)
  NoOfLines=NoOfLines+1
WEND
CloseFile(hFile)
NoOfLines=NoOfLines-1
PRINT FileName + " Contains "+ str(NoOfLines) + " lines."
end: