Next: break
Statement, Previous: while
Statement, Up: Loop Statements [Contents][Index]
do-while
StatementThe do
–while
statement is a simple loop construct that
performs the test at the end of the iteration.
do body while (test);
Here, body is a statement (possibly a block) to repeat, and test is an expression that controls whether to repeat it again.
Each iteration of the loop starts by executing body. Then it computes test and, if it is true (nonzero), that means to go back and start over with body. If test is false (zero), then the loop stops repeating and execution moves on past it.
Warning: Human beings tend to confuse the do
–while
statement with the while
statement using the null statement
as its body (see Null Statement). To avoid that, consistently
mark such constructs with a specific comment or with clearly different
indent styles.