Nested for loops

Edit on Github instead

You can nest, or include, for loops inside of other for loops as well. For example:

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

i is 0 and j is 0
i is 0 and j is 1
i is 0 and j is 2
i is 0 and j is 3
i is 1 and j is 0
i is 1 and j is 1
i is 1 and j is 2
i is 1 and j is 3
i is 2 and j is 0
i is 2 and j is 1
i is 2 and j is 2
i is 2 and j is 3

Suggest changes

Related links

URL Topic Source