https://kotlinlang.org logo
Title
k

Kavin

08/12/2019, 11:57 AM
But we can skip the index if we need?
s

Shawn

08/12/2019, 12:03 PM
return
should cause the calling function to return since the lambda isn’t marked as
crossinline
you should be able to
return@forEachIndexed
which will, essentially, break the “loop”
d

diesieben07

08/12/2019, 12:04 PM
It will act like continue, not break.
k

Kavin

08/12/2019, 12:04 PM
But this just skip the index. Like if the condition passes on 5th index and I have
return@forEachIndex
it just skips the index 5 and continues with the next index i.e, 6th.
d

diesieben07

08/12/2019, 12:04 PM
If you need true break and continue I suggest just using a normal for loop
for ((index, value)  in list.withIndex()) {

}
a

arekolek

08/12/2019, 12:04 PM
takeWhile
/
takeUntil
?
👍 1
s

Shawn

08/12/2019, 12:04 PM
@corneil brings up a good point though - you might be misapplying imperative concepts to a functional construct
k

Kavin

08/12/2019, 12:05 PM
Yeah @diesieben07 is right!
Yeah I found the alternative ways but just that I wanted to know whether it can be done or not! By the way we can do it by both @corneil and @arekolek ways!