https://kotlinlang.org logo
Title
s

Shawn

02/08/2018, 6:32 PM
from inside a foreach? isn’t that returning from the lambda you’re passing to foreach
k

kevinmost

02/08/2018, 6:37 PM
No, that would be
return@forEach
.
return
by default will return to the outermost scope
s

Shawn

02/08/2018, 6:38 PM
ah, true
so in the
.forEach { return 0 }
example, is
return
legal because it’s used to return from the outer function early?
k

kristofdho

02/08/2018, 7:57 PM
well in this context, the
forEach
is the outermost scope
exactly the same happens with
run
,
let
, etc etc
k

kevinmost

02/08/2018, 8:07 PM
it isn't, the function is the outermost scope. His example does not hit
error
, it returns early with the value of
0
k

kristofdho

02/08/2018, 8:14 PM
i'm fooling around with it and there is some weird behaviour indeed
a

alllex

02/09/2018, 9:50 AM