While...End While Statement


While...End While Statement

Syntax

     While condition        [statements]        [Exit While]        [statements]        [Continue While]        [statements]     End While 


condition (required; Boolean)

An expression that is reevaluated each pass through the loop


statements (optional)

Program statements to execute while condition remains true

Description

The While...End While statement repeatedly executes program code while a given condition remains true. The loop block is executed each time condition evaluates to true; the entire loop is skipped once condition evaluates to False. The Exit While statement can be used at any time to exit the While statement early.

New in 2005. The Continue While statement can be used at any time to immediately jump back to the top of the loop and attempt to process the next iteration. The condition is reevaluated immediately upon reaching the top of the loop.

Usage at a Glance

  • A Nothing condition is evaluated as False.

  • You can nest While...End While loops within each other.

  • The While...End While statement is a subset of the more flexible Do...Loop statement.

Version Differences

  • In VB 6, the ending clause that accompanies the While construct is Wend; in .NET, it is EndWhile.

  • Visual Basic 2005 includes the Continue While statement.

See Also

Do...Loop Statement




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net