0 原文
1. For 循環
對集合進行迭代
fun main(args : Array<String>) {
var list = listOf("No1", "No2", "No3")
// For 循環
for (i in list) {
println(i)
}
// For 循環,並打印下標 index
for (index in list.indices) {
println("Index is $index, and the value is ${list[index]}")
}
}
運行結果
No1
No2
No3
Index is 0, and the value is No1
Index is 1, and the value is No2
Index is 2, and the value is No3
Process finished with exit code 0