This is a C programming technique for repeating a block of code while some condition is met.
The syntax is as follows:
do { // Loop body } while (<condition to reenter the loop>)
Graphically, we can represented this as follows:
Note:
- The loop body is always executed at least once (contrast to while loops)
- The condition to reenter the loop is evaluated after – if met, the loop body is repeated, otherwise the loop exits.
- that the condition to enter the loop body is reevaluated each time around the loop.
break and continue
As with the for-loop, it is possible to jump to the end of a loop block with the continue statement and break out of the loop early with the break statement.
See also: while-loop; for-loop