Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
do...while Statement

do...while Statement

Executes a statement block once, and then repeats execution of the loop until a condition expression evaluates to false.

do
   statement
while (expression)

statement

Required. Statement to be executed if expression is true. Can be a compound statement.

expression

Required. An expression that can be coerced to Boolean true or false. If expression is true, the loop is executed again. If expression is false, the loop is terminated.

Unlike the while statement, a do...while loop is executed one time before the conditional expression is evaluated.

On any line in a do…while block, you can use the break statement to cause the program flow to exit the loop, or you can use the continue statement to go directly to the while expression.

In the following example, the statements in the do...while loop execute as long as the variable i is less than 10.

var s = "";

var i = 0;
do
{
    s +=  i + " ";
    i++;
} while (i < 10);

print (s);
// Output: 0 1 2 3 4 5 6 7 8 9 

Community Additions

ADD
Show:
© 2015 Microsoft