O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

While...End While Statement

Syntax

While condition
   [statements]
[Exit While]
   [statements]
End While
condition (required; Numeric or String)

An expression evaluating to True or False

statements (optional)

Program statements to execute while condition remains True

Exit While (optional; Keyword)

Exits the While loop

Description

Repeatedly executes program code while a given condition remains True

Rules at a Glance

  • A Null condition is evaluated as False.

  • If condition evaluates to True, the program code between the While and End While statements is executed. After the End While statement is executed, control is passed back up to the While statement where condition is evaluated again. When condition evaluates to False, program execution skips to the first statement following the End While statement.

  • You can nest While...End While loops 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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required