do while Loop Program
Every loop consists of three parts in sequence:
- Initialization: Use to initialize the loop variable.
- Condition: It is checked after each iteration as an entry point to the loop.
- Updation: Incrementing the loop variable to eventually terminate the loop not satisfying the loop condition.
Here is the C language tutorial explaining do while Loop → do while Loop in C
Do while loop is used when the actual code must be executed atleast once. For example: Incase of menu driven functions.
Below is a simple program on do while loop.
printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
always declare the variables before using them
int i = 10; // declaration and initialization at the same time
do // do contains the actual code and the updation
printf("i = %d\n",i);
i = i-1; // updation
// while loop doesn't contain any code but just the condition
while(i > 0);
printf("\n\The value of i after exiting the loop is %d\n\n", i);
printf("\n\n\t\t\tCoding is Fun !\n\n\n");