1.for循环
//方法1
for(arg in args){
//TODO
}
//方法2
for(arg in args)
//TODO
//方法3,直接使用索引
for (i in array.indices) {
print(array[i])
}
//方法4,直接根据索引获取值
for ((index, value) in array.withIndex()) {
println("the element at $index is $value")
}
2.while循环
while (x > 0) {
x--
}
do {
val y = retrieveData()
} while (y != null) // y is visible here!
网友评论