do Post-test loop
do Post-test loop
do while tests after the body, so it runs at least once and suits retries. Nonzero repeats, continue reaches the test, and the semicolon is required.
| Category | Control flow |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
do statement; while (expr);
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
attempt 1
attempt 2
🏷️ Related control-flow keywords
📚 Related Tutorials
❓ FAQ
QDoes do while still execute if its condition is initially 0?
AYes. The body executes once because the first condition test comes after it. The subsequent evaluation of 0 exits the loop without a second iteration.
QCan the final semicolon in do while be omitted?
ANo. The complete form is do statement while (expression);, and the final semicolon is part of that syntax. Unlike an ordinary while loop, omitting it usually causes a compilation error.
QWhere does continue jump in a do while loop?
AIt skips the rest of the body and evaluates the while condition at the end rather than unconditionally starting another iteration. If that condition is false, the loop still exits.