do (C# Reference)

The do statement executes a statement or a block of statements while a specified boolean expression evaluates to true. Because that expression is evaluated after each execution of the loop, a do-while loop executes one or more times. This differs from the while loop, which executes zero or more times.

At any point within the do statement block, you can break out of the loop by using the break statement.

You can step directly to the evaluation of the while expression by using the continue statement. If the expression evaluates to true, execution continues at the first statement in the loop. Otherwise, execution continues at the first statement after the loop.

You also can exit a do-while loop by the goto, return, or throw statements.


The following example shows the usage of the do statement. Select Run to run the example code. After that you can modify the code and run it again.

int n = 0;
} while (n < 5);

C# language specification

For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

See also

C# Reference
C# Programming Guide
C# Keywords
do-while Statement (C++)
Iteration Statements
while statement