Export (0) Print
Expand All

8.8.1 The while statement

Visual Studio .NET 2003

The while statement conditionally executes an embedded statement zero or more times.

while-statement:
while   (   boolean-expression   )   embedded-statement

A while statement is executed as follows:

  • The boolean-expression (Section 7.16) is evaluated.
  • If the Boolean expression yields true, control is transferred to the embedded statement. When and if control reaches the end point of the embedded statement (possibly from execution of a continue statement), control is transferred to the beginning of the while statement.
  • If the Boolean expression yields false, control is transferred to the end point of the while statement.

Within the embedded statement of a while statement, a break statement (Section 8.9.1) may be used to transfer control to the end point of the while statement (thus ending iteration of the embedded statement), and a continue statement (Section 8.9.2) may be used to transfer control to the end point of the embedded statement.

The embedded statement of a while statement is reachable if the while statement is reachable and the Boolean expression does not have the constant value false.

The end point of a while statement is reachable if at least one of the following is true:

  • The while statement contains a reachable break statement that exits the while statement.
  • The while statement is reachable and the Boolean expression does not have the constant value true.
Show:
© 2014 Microsoft