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.

CategoryControl flow
KindKeyword / Statement
C standardC89 / 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏