Example for do..while loop

Example for do..while loop:
#include< stdio.h >
main()
{
int n=10,i=12;

do
{
printf("C Language");
i++;
}while(i<=n);

}

In the above example we see that, Program start with initiliazing 10 to n and 12 to i. When do keyword occur control of execution directly enters into the body of loop to print a message "C Language" and increment variable i's value by 1 so i variable value is now 13. After this point it come to loop condition part i.e. while(i<=n); where i is 13 and and n is 10. Hence condition 13<=10 is evaluated to false and continues execution with statement written after the do while looping statement. At first time itself the condition was false, but even though the body of loop is executed one time. This does not happen in case of while loop.

Comments