do...while loop in C


In privious post we learned working of for loop and while loop, in this post we learn working of do....while loop.

do..while loop is similar to while loop only difference is-
do...while loop check condition at the end of loop. That means the statement inside the do...while loop are executed at least once even if condition is false.




    Syntax of do...while loop:



Syntax of do..while loop is shown above.




    Example program of do-while loop:


#include<stdio.h>
void main()
{
int i;
do 
{
   printf("You are inside the do while loop\n");
   printf("Press 1:to exit from the loop\n");
   scanf("%d",&i);
}
while(i!=1);

printf("You are out of the do while loop\n");
}


Above program shows the following output:





No comments:

Post a Comment

If you have any doubts, please discuss here...👇