Nested Loops Flashcards

1
Q

Define a nested loop !

A

A nested loop in Java is a loop that exists inside another loop. The outer loop controls the number of iterations for the inner loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give an example of multiple combinations !

A

EXAMPLE 1 :

for (int i = 0; i < outerLimit; i++) {
for (int j = 0; j < innerLimit; j++) {
// Inner loop body
}
// Outer loop body
}

EXAMPLE 2 :

for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 2; j++) {
System.out.println(“Outer: “ + i + “, Inner: “ + j);
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly