Opening Hours :7AM to 9PM
do
{
...
...
}while(condition);
In the above syntax if the condition is true the statements of do while block is execute infinite times, if the condition is false the statements of do while block is executed one time
class Main
{
public static void main(String args[])
{
int x=1;
do
{
System.out.println(x);
x++;
}while(x<=10);
}
}
class Main
{
public static void main(String args[])
{
int x=10;
do
{
System.out.println(x);
x--;
}while(x>=1);
}
}
Nested Do While Loop :
One Do While loop within another Do While loop is knows as Nested Do While Loop
Syntax
do
{
do
{
...
...
}while(condition);
...
..
}while(condition);
class Main
{
public static void main(String args[])
{
int x=1,y;
do
{
y=1;
do
{
System.out.print("*");
y++;
}while(y<=3);
System.out.println();
x++;
}while(x<=6);
}
}
class Main
{
public static void main(String args[])
{
int x=1,y;
do
{
y=6;
do
{
System.out.print("*");
y--;
}while(y>=x);
System.out.println();
x++;
}while(x<=6);
}
}