I don't understand foreach{ } in kotlin. help me ! thanks you


#1

fun f1() {
(1…4).forEach {
if (it == 2) return
print(it)
}
}

fun f2() {
(1…4).forEach(fun(it) { // closure
if (it == 2) return
print(it)
})
}

fun main(args: Array) {
f1()
f2()
}


#2

non-local return