O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

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 Statement

The while statement evaluates its condition before entering the loop body on every iteration. If evaluation of the condition at the end of the loop is desired, the do statement is your choice:

do    embedded statementwhile (condition);

(Don’t forget the semicolon at the end of the last line.) An implication of this loop structure is that the body of the loop runs at least once. Control simply falls into the loop at the start, and when the condition at the end evaluates positively, control is transferred to the beginning of the loop body again.

As with the while statement, the break and continue statements can be used in a do statement’s embedded statement, too.

Note: Code Maintenance Caveat

Because I once spent a couple ...

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