“`” 在最外层循环前加一个标记如outfor,然后用break outfor;可以跳出多重循环。例如以下代码:

</p>

<pre><code>public class TestBreak { public static void main(String[] args) { outfor: for (int i = 0; i < 10; i++){ for (int j = 0; j < 10; j++){ if (j == 5){ break outfor; } System.out.println(""j = "" + j); } } }}</code></pre>

运行结果如下所示:

j = 0

j = 1

j = 2

j = 3

j = 4

<pre><code> "“`

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.