Reputation: 14505
Kotlin has the follow for
for (i in 0..10) {}
it is similar to Java
for (int i = 0; i < 10; i++) {}
but how change the increment in kotlin to get something like it in java:
for (int i = 0; i < 10; i = i + 2) {}
Upvotes: 36
Views: 18836
Reputation: 10810
for (i in 1..4 step 2) print(i) // prints "13"
See here: http://kotlinlang.org/docs/reference/ranges.html
Upvotes: 47