Skip to content
Advertisement

Is there any way to do n-level nested loops in Java?

In other words, can I do something like

for() {
    for {
       for {
       }
    }
}

Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another?

Of course, the idea is that there should be an “easy” or “the usual” way of doing it. I already have an idea for a very complicated one.

Advertisement

Answer

It sounds like you may want to look into recursion.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement