In while loop the condition is evaluated first and then executes the body of loop and if the condition is not satisfied even at the very first attempt the body of the loop is not executed. But sometimes we may need the statement which must be executed at first attempt even the condition is not satisfied so there we use the do-while.
Syntax:
do
{
Body of loop
}
while(condition);
in the above syntax the body of the loop is must be executed even the condition is not satisfied because in this the condition is evaluated after the body, so it is provides exit-control loop.
e.g:
do
{
System.out.println(“java”);
a=a+1;
}
while(a<1);
Let suppose ‘a’ is initialized at 1 then it will print ‘java’ only one time.