You can't mutate the current element, you would need to use a while loop instead:
var i = 0
while (i <= n) {
// do something
if (someCond) {
i++ // Skip the next iteration
}
i++
}
What are you trying to do? There is a chance there is a more idiomatic way to do this.
If you could restructure this logic to skip the current iteration, why not use continue:
for (i in 0..n) {
if (someCond) {
continue
}
// ...
}
Side note: .. ranges are inclusive, so to loop through e.g. a list of size n you usually need 0..(n - 1) which is more simply done with until: 0 until n.
In your specific case, you can use windowed (Kotlin 1.2):
list.asSequence().filter { someCond }.windowed(2, 1, false).forEach {
val (first, second) = it
// ...
}
asSequence will convert the list into a Sequence, removing the overhead of filter and windowed creating a new List (as they will now both return Sequences).
If you want the next pair to not include the last element of the previous pair, use windowed(2, 2, false) instead.