Please enable JavaScript to use CodeHS

CodeHS Glossary


Nested For Loop Java

A for loop written, or “nested”, inside of another for loop. For example:

for(int i = 0; i < 5; i++){
    for(int j = 0; j < 3; j++){
        System.out.println(i + " " + j);
    }
    System.out.println("");
}

This would print out:

0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
3 0
3 1
3 2
4 0
4 1
4 2