Javaで複数のループ(2つのループを含む)から抜け出す方法
How Break Out Multiple Loops Java
問題: 次のように、ブレークはループからジャンプすることしかできません。
while(true){ for (int i = 1 i = l) { System.out.println('T' + '
' + t2) break //if not included, the break can only jump out of the for loop, but not out of the while loop } } }
解決: 次のように、labelステートメントを使用して多層ループから抜け出すことができます。
look: //Use the mark statement look, you can write other statements, such as a: b: etc. while(true){ for (int i = 1 i = l) { System.out.println('T' + '
' + t2) break look // Jump out of the while statement directly } } }