Nested Loops in Java


Nested loops are loops inside a loop. They are useful for patterns, accessing elements in multi-dimensional arrays, etc.

Source Code

for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= i; j++) {
        System.out.print("* ");
    }
    System.out.println(); // Move to the next line
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments