「Kotlin入門」forループのサンプル
構文
for (item: Int in ints) {
// some code
}
サンプルコード
fun main(args: Array<String>) { val items = listOf("apple", "banana", "pear") for (item in items) { println(item) } for (index in items.indices) { println("item at $index is ${items[index]}") } }
実行結果
apple
banana
pear
item at 0 is apple
item at 1 is banana
item at 2 is pear