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 ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.