Opening Hours :7AM to 9PM
while(condition)
{
...
...
}
class Main
{
public static void main(String args[])
{
int x=1;
while(x<=10)
{
System.out.println(x);
x++;
}
}
}
class Main
{
public static void main(String args[])
{
int x=10;
while(x>=1)
{
System.out.println(x);
x--;
}
}
}
Nested While Loop :
One While loop within another While loop is knows as Nested While Loop
Syntax
while(condition)
{
while(condition)
{
...
...
}
...
..
}
class Main
{
public static void main(String args[])
{
int x=1,y;
while(x<=6)
{
y=1;
while(y<=3)
{
System.out.print("*");
y++;
}
System.out.println();
x++;
}
}
}
class Main
{
public static void main(String args[])
{
int x=1,y;
while(x<=6)
{
y=6;
while(y>=x)
{
System.out.print("*");
y--;
}
System.out.println();
x++;
}
}
}