Ben Chuanlong Du's Blog

It is never too late to learn.

Returns and Jumps in Kotlin

Break at label is a convenient way to jump out of a nested loop.

In [3]:
loop@ for (i in 1..5) {
    for (j in 1..5) {
        if (j > 1) break@loop
        println("i: ${i}, j: ${j}")
    }
}
i: 1, j: 1
Out[3]:
null
In [ ]:

Comments