If we specify a loop inside another loop then it is called as nested loop. Any loop can be specified inside any other loop any number of times.
Program:
class NestedForLoop{
public static void main(string[] args) {
for(int i=1; i<=5;i++) {
for(int j=1; j<=5;j++) {
System.out.println("*");
}
System.out.println();
}
}
}
Program
lass NestedWhileLoop{
public static void main(string[] args) {
int i=1;
System.out.println("Tables");
while(i<=10) {
int j=1;
while(j<=10) {
System.out.println(i+"*"+j+"="+(i*j));
j++;
}
i++;
System.out.println();
}
}
}