Search code examples
loopskotlincontinue

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.


Solution

  • repeat(n){
        blah()
    }
    

    Will execute blah() n times.