The do while loop is same as a while loop except that here the Boolean condition checks after the execution of the loop body, because of this the do while loop is an exit control loop.
Syntax:
do
{
loop body;
}while(condition);
Example:
class DoWhileDemo
{
public static void main(String args[])
{
do
{
System.out.println("I execute once even the condition is false");
}while(false);
}
}
output:
In the example you can see that the loop body executes once even if the condition is a false one at the beginning of the loop.
Syntax:
do
{
loop body;
}while(condition);
Example:
class DoWhileDemo
{
public static void main(String args[])
{
do
{
System.out.println("I execute once even the condition is false");
}while(false);
}
}
output:
Comments
Post a Comment