continue_vs_return.kt
# coroutines
j
continue_vs_return.kt
Does it bother anyone else that repeat(x) doesn’t count as a loop so you have to use
return
instead of `continue`/`break`?
r
No.
1
Do you use
break
or
continue
in
forEach
?
j
no because I can’t, but it would make sense to me to do so
though I understand that it’s not technically a loop
r
Well it doesn’t for me because you should know that you’re using a lambda, which has a much bigger cost than a normal loop
👍 1
l
Well,
repeat
is inline and doesn't really cost more than a
for
or
while
loop
☝️ 1
But the semantics are different.
repeat
is a just a higher order function (a function that takes another one, called a lambda), while
for
,
while
, `do`/`while` are part of the control flow, similar to `if`/`else`, but with the added fact that they can loop.
j
so doesn’t that imply by Gael’s logic that
continue
should be applicable?
l
No,
continue
works only for raw control flow constructs like
while
j
That does make sense logically
l
skipping code is not possible. In a lambda, you can only run, return or throw. returning to the lambda works the same as
continue
though, so in practice, there's not much difference
Well, skipping code is possible with
if
, but you can't jump out of a lambda out of nowhere, unless that lambda is inline and you return to the function it's inlined in.
j
thanks for clarifying