ラベルをつけてループ処理を書くことで、多重のループ処理内から一気に抜け出すことができます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loop1:for var i=0 ; i<10 ; i++ { | |
if i==6 { | |
break loop1 | |
} | |
println("▲:\(i)") | |
loop2:for var j=0 ; j < 5 ; j++ { | |
println("◯:\(j)") | |
if j==3 { | |
break loop1 | |
} | |
} | |
} |
▲:0
◯:0
◯:1
◯:2
◯:3
こうなります。