[lang-ref] ( break_out_of_nested_loop ) ( kotlin )
@Test
fun breakOutOfNestedLoop() {
// break@outer
val limitValue = 25
var currentValue = 0
for (i in 1 until 10) {
for (j in 1 until 10) {
currentValue = i * 10 + j
if (currentValue == limitValue) {
break // this breaks only inner loop
}
}
}
assertEquals(currentValue, 99)
outer@ for (i in 1 until 10) {
for (j in 1 until 10) {
currentValue = i * 10 + j
if (currentValue == limitValue) {
break@outer
}
}
}
assertEquals(currentValue, limitValue)
}