有没有办法在 Java 中进行 n 级嵌套循环? [英] Is there any way to do n-level nested loops in Java?

查看:27
本文介绍了有没有办法在 Java 中进行 n 级嵌套循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

换句话说,我可以做类似的事情

In other words, can I do something like

for() {
    for {
       for {
       }
    }
}

除了N次?换句话说,当创建循环的方法被调用时,它被赋予一些参数 N,然后该方法会创建 N 个嵌套在另一个循环中的循环?

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.

推荐答案

听起来您可能想要查看 递归.

It sounds like you may want to look into recursion.

这篇关于有没有办法在 Java 中进行 n 级嵌套循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆