Information Technology Reference
In-Depth Information
The
do
loop has several characteristics that set it apart from other flow-of-control con-
structs. They are the following:
The body of the loop,
Statement
, will always be executed at least once, even if
TestExpr
is
initially
false
.
The semicolon is required after the closing parenthesis of the test expression.
The following code shows an example of a
do
loop:
int x = 0;
do
Console.WriteLine("x is {0}", x++);
while (x<3);
↑
Required
This code produces the following output:
x is 0
x is 1
x is 2