do-while Loop in C
do-while tests at the bottom: the body always runs at least once, then repeats while the condition holds. That guarantee makes it the menu/prompt loop — show options first, then ask whether to continue.
The trailing semicolon (} while (...);) is mandatory and unique among loops. Prefer plain while when zero iterations must be possible; reach for do-while exactly when the first pass is unconditional.
Body first, test after
do { ... } while (cond); runs the block, then checks — one execution guaranteed regardless.
Don't forget the semicolon
The closing }; is required — missing it is a compile error at a confusing line.
Menus are the use case
Display options, read a choice, repeat while not-quit — the prompt must appear before any test decides.
while vs do-while
Zero-or-more means while; one-or-more means do-while — choosing by that sentence never goes wrong.
#include <stdio.h> int main(void) { int choice = 0; int shows = 0; do { ++shows; choice = 9; } while (choice != 9); printf("shown %d time(s)\n", shows); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.