O'Reilly logo

C# Primer Plus by Klaus Michelsen

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

The do-while Loop Statement

The do-while loop is analogous to the while loop in that the loop body is repeatedly executed over and over again as long as the Boolean expression is true. However, there is one important difference—the loop body, located between the keywords do and while (see Syntax Box 9.2), is executed before the Boolean expression is evaluated. Consequently, the loop body of the do-while loop is always executed at least once, even if the Boolean expression is false initially.

Syntax Box 9.2 The do-while Statement

						do_while_statement:=
     do
       <Loop_body>
     while (<Loop_condition>);

where:

						<Loop_body>::= <Statement>;
           ::= <Compound_statement>

<Loop_condition>::= <Boolean expression>

Note:

  • The <Loop_body> is repeated as long as <Loop_condition> ...

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