WHILE...WEND

From QB64 Wiki

Revision as of 18:26, 3 October 2011 by Clippy (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The WHILE...WEND statement is used to repeat a block of statements while the condition is met.


Syntax:

WHILE condition
.
.
.
WEND


Description:

  • condition is a numeric expression used to determine if the loop will execute.
  • statements will execute repeatedly while condition is a non-zero value.
  • EXIT WHILE can be used for emergency exits from the loop in QB64 only.
  • A DO...LOOP can use the same DO WHILE condition to get the same results.
  • WHILE loops only run if the WHILE condition is True.


Relational Operators:

  • > is Greater than
  • < is Less than
  • = is Equal to
  • >= is Greater than or Equal to
  • <= is Less than or Equal to
  • <> is Not Equal to


Code Examples:

Example 1: Reading an entire file. Example assumes the program has a file opened as #1

OPEN "Readme.txt" FOR INPUT AS #1 WHILE NOT EOF(1) _LIMIT 1 'limit line prints to one per second LINE INPUT #1, text$ IF INKEY$ = CHR$(27) THEN EXIT WHILE 'ESC key exits PRINT text$ WEND

Example 2: Clearing the keyboard buffer.

WHILE INKEY$ <> "" : WEND


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page