Hello! How can one write something like this in Ko...
# getting-started
c
Hello! How can one write something like this in Kotlin?
Copy code
let finished = false
for (let i = 0; i < restrictions.length && !finished; i++) {

      finished = ...

    }
d
break
with
for (i in 0 until restrictions.length)
?
👆 1
d
Depending on what
restrictions
is, you might be able to use
for (i in restrictions.indices)
or even just
for (element in restrictions)
c
The only problem I have is the comparation with
!finished
. Should I just break inside the
for
?
👌 8
c
val finished = restrictions.any { ... }
for a more ideomatic approach
s
@Casey Brooks I wouldn’t necessarily call that more idiomatic depending on what logic is actually in the for body — if there’s side effects or any particularly complex logic that determines when the loop is finished (or maybe even how
i
advances), then
.any {}
wouldn’t be the right tool for the job
c
Thanks for you answers! It worked out just fine with the first answer, thanks @Dominaezzz
👍 1