val items = listOf("apple","banana","kiwifruit") for(item in items){ println(item) } for(index in items.indices){ println("item at $index is ${items[index]}") }
while循环
1 2 3 4 5
val items = listOf("apple","banana","kiwifruit") var index = 0 while(index < item.size){ println("item at $index is${items[index]}") }