C.17 dowhile Repetition Statement

The do…while repetition statement is similar to the while statement. In the while, the program tests the loop-continuation condition at the beginning of the loop, before executing the loop’s body; if the condition is false, the body never executes. The dowhile statement tests the loop-continuation condition after executing the loop’s body; therefore, the body always executes at least once. When a dowhile statement terminates, execution continues with the next statement in sequence. Figure C.16 uses a dowhile (lines 10–14) to output the numbers 1–10.

Fig. C.16 dowhile repetition statement

Computer code has 18 lines plus output.

Get Android How to Program, 3/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.