Control Flow
Do While Loop
A do while loop runs the body once before checking the condition.
Do While Loop
do_while_loop.c
#include <stdio.h>
int main(void) {
int value = ;
int visits = 0;
do {
visits++;
value--;
} while (value > 0);
printf("visits=%d\n", visits);
return 0;
}
#include <stdio.h>
int main(void) {
int value = ;
int visits = 0;
do {
visits++;
value--;
} while (value > 0);
printf("visits=%d\n", visits);
return 0;
}
#include <stdio.h>
int main(void) {
int value = ;
int visits = 0;
do {
visits++;
value--;
} while (value > 0);
printf("visits=%d\n", visits);
return 0;
}
do while
`do { ... } while (condition);` checks after the first run.
at least once
The body executes even when the condition starts false.