In do while loop, loop is executed once before checking condition.defference between while loop and do while loop:
While loop first checks condition and then executes the loop but in do while loop, loop is executed once and then it checks the condition. it is little difficult to understand by this. Let us see syntax and example for it....
SYNTAX:
do
{
statements;
}
while(condition);
Example:
#include<stdio.h>
#include<conio.h>
main()
{
int x=1;
clrscr();
do
{
printf("%d\n",x);
x++;
}
while(x>=2&&x<=10);
getch();
}
While loop first checks condition and then executes the loop but in do while loop, loop is executed once and then it checks the condition. it is little difficult to understand by this. Let us see syntax and example for it....
SYNTAX:
do
{
statements;
}
while(condition);
Example:
#include<stdio.h>
#include<conio.h>
main()
{
int x=1;
clrscr();
do
{
printf("%d\n",x);
x++;
}
while(x>=2&&x<=10);
getch();
}