class NestedForLoop {
public static void main(String[] args) {
for (int i = 1; i <= 5; ++i) {
System.out.println("Outer loop iteration " + i);
for (int j = 1; j <=2; ++j) {
System.out.println("i = " + i + "; j = " + j);
}
}
}
}
When you run the program, the output will be:
Outer loop iteration 1
i = 1; j = 1
i = 1; j = 2
Outer loop iteration 2
i = 2; j = 1
i = 2; j = 2
Outer loop iteration 3
i = 3; j = 1
i = 3; j = 2
Outer loop iteration 4
i = 4; j = 1
i = 4; j = 2
Outer loop iteration 5
i = 5; j = 1
i = 5; j = 2
To Learn More: Click Here
Comments
Post a Comment