标签的使用
loop@ for (i in 1..100) {
for (j in 1..100) {
if (……) break@loop
}
}
从lambda中跳出来
如下的return会直接把foo方法结束掉
fun foo() {
ints.forEach {
if (it == 0) return
print(it)
}
}
这样的隐式标签可以跳出到lambda的调用处
fun foo() {
ints.forEach {
if (it == 0) return@forEach
print(it)
}
}