O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

More do and while

Whereas a while loop evaluates the termination condition before the code block is executed (at the top of the loop), it makes sense to evaluate that condition at the end of the code block when you need to be sure that the loop will execute at least once. In other words, you want the condition to be evaluated at the bottom of the loop.

A do . . . while loop consists of a set of statements contained within braces that are executed for as long as a given condition evaluates to true (that is, it succeeds). The do keyword starts the loop, and the while statement provides the condition testing mechanism and is identical to the while statement that might appear at the top of the loop in place of the do.

All that’s been done here is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required