Name
While...End While Statement
Syntax
Whilecondition[statements] [Exit While] [statements] End While
-
condition(required; Numeric or String) An expression evaluating to
TrueorFalse-
statements(optional) Program statements to execute while condition remains
True-
ExitWhile(optional; Keyword) Exits the While loop
Description
Repeatedly executes program code while a given condition remains
True
Rules at a Glance
A
Nullcondition is evaluated asFalse.If
conditionevaluates toTrue, the program code between theWhileandEndWhilestatements is executed. After theEndWhilestatement is executed, control is passed back up to theWhilestatement whereconditionis evaluated again. Whenconditionevaluates toFalse, program execution skips to the first statement following theEndWhilestatement.You can nest
While...EndWhileloops within each other.
Programming Tips and Gotchas
The While...End
While statement
remains in Visual Basic for backward compatibility only. In our
opinion, it has been superceded by the much more flexible
Do...Loop statement.
VB.NET/VB 6 Differences
In VB 6, the ending statement that accompanies the
While construct is Wend; in
VB.NET, it is End
While.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access