Otherwise, I'm afraid the general case is simply to use a while loop instead, as you suggest: var i = 1Īs you say, this of course more awkward: the initial value, increment/decrement, and final value are now in three different places, and so the loop is harder to read. This can make the loop clearer and more concise but it only applies in some specific cases. First, in some cases you may be able to include the jumps in the iteration itself - perhaps iterating over the result of some process, instead of over a simple range. As you've found, the index of a …in… for loop is read-only in Kotlin you can't change it within the loop.
0 Comments
Leave a Reply. |