How to for loop with var i


#1

Hi, Please suggest how to implenent example with loop in Kotlin with for loop

java sample
int p = 2;                   
for (int i = 0; i < 10; i=i+2) {
  if (i == p) {//p - some unknow step
  // skip some steps           
  i = 5;           
  }                   
}                          

how to implement the same with kotlin range loop  ???
for([var] i in 0…10){ //not val
i ==5//error i is val
}

but not with wile loop
var i: Int = 0
           while (i < 10){
           if (i == p){
                   i = 6
           }
           i = i + 2
}

I want for loop with var i value
Thanks)


For-loop dynamic step
#2

Kotlin does not support mutation of loop index variables, and we have no plans to do it. Tha main reason is that there are extremely few realistic use cases for this feature.