Kevin Huang
11/08/2018, 2:25 AMgoto
.
And in lambdas,can't call "return" directly. In some complex cases , can't return a value immediately , need some ugly code to solve.
Any suggests for this situation?
Thanks.gildor
11/08/2018, 2:25 AMgoto
, it’s just return to outer scopeKevin Huang
11/08/2018, 2:35 AMfun foo() {
listOf(1, 2, 3, 4, 5).forEach {
if (it == 3) return // non-local return directly to the caller of foo()
print(it)
}
println("this point is unreachable")
}
It may make me understand the wrong logic.
At the beginning i thing the "return" just break the forEach
but not return directly to the caller of foo().Shawn
11/08/2018, 2:59 AMgildor
11/08/2018, 3:08 AMKevin Huang
11/08/2018, 3:19 AMgildor
11/08/2018, 3:36 AMKevin Huang
11/08/2018, 3:40 AMgildor
11/08/2018, 3:43 AMreturn
work yes, it can be not obviousShawn
11/08/2018, 3:47 AMKevin Huang
11/08/2018, 3:52 AMreturn
in closure is not for closure , it's for the outer function. Is it right?gildor
11/08/2018, 3:55 AMKevin Huang
11/08/2018, 3:56 AM