Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

continue n times in kotlin loop

Is it possible to continue n times in a kotlin loop?

for(i in 0..n){
    doSomething()
    if(condition){
       //manipulate n
    }
}

Since i for some reason is a val I cannot seem to reinitialize it in the loop.

like image 678
Jonas Grønbek Avatar asked Feb 12 '19 14:02

Jonas Grønbek


People also ask

How do you continue a loop in Kotlin?

How labeled continue works? Label in Kotlin starts with an identifier which is followed by @ . Here, outerloop@ is a label marked at outer while loop. Now, by using continue with the label ( continue@outerloop in this case), you can skip the execution of codes of the specific loop for that iteration.


1 Answers

repeat(n){
    blah()
}

Will execute blah() n times.

like image 160
John Doe Avatar answered Nov 15 '22 08:11

John Doe