do-while Loop Statement

do while loop statement allows you to execute code block in loop body at least one. Here is do while loop syntax:

do {
// statements
} while (expression);

Here is an example of using do while loop statement:

#include <stdio.h>
void main(){
int x = 5;
int i = 0;
// using do while loop statement
do{
i++;
printf("%d\n",i);
}while(i < x);

}

The program above print exactly 5 times as indicated in do while loop body

No comments:

Post a Comment