do-while Statement (GNU C Language Manual)

Next: , Previous: , Up: Loop Statements [Contents][Index]


19.6.2 do-while Statement

The dowhile 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 dowhile 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.

AltStyle によって変換されたページ (->オリジナル) /