do {
n++;
total += values[n];
}
while (total < 10);As you've probably noticed, this is basically an upside-down version of the previous while example. There is one difference: With the do loop, the condition is tested at the end of the loop. This means that the statements in the loop will always be executed at least once, even if the condition is never true.
By the Way
As with the for and while loops, the do loop can include a single statement without braces, or a number of statements enclosed in braces.