标签: java for-loop kotlin
Kotlin有
for (i in 0..10) {}
它类似于Java
for (int i = 0; i < 10; i++) {}
但是如何在kotlin中改变增量来获得类似的东西:
for (int i = 0; i < 10; i = i + 2) {}
答案 0 :(得分:16)
for (i in 1..4 step 2) print(i) // prints "13"
见这里:http://kotlinlang.org/docs/reference/ranges.html