美文网首页
kotlin速成之道:loop

kotlin速成之道:loop

作者: 钱晓缺 | 来源:发表于2021-03-05 13:07 被阅读0次

```

for (i in list){}

```

键值对循环

```

var map = mapof(1 to "one", 2 to "two", 3 to "three")

for ((key, value) in map){}

```

fun mapLoop(map:Map) {

for ((key,value)in map) {

println("$key")

}

}

public fun indexLoop(list:List) {

for ((index,value)in list.withIndex()) {

println("$index: $value")

}

}

fun numLoop(i:Int) {

for (i in 1..9 ) {

println(i)

}

for (i in 1 until 9 ) {

println(i)

}

for (i in 9 downTo 1 step 2) {

println(i)

}

}

fun charLoop(c:String):Unit {

for (i in c) {

println(i)

}

}

相关文章

网友评论

      本文标题:kotlin速成之道:loop

      本文链接:https://www.haomeiwen.com/subject/qplsfltx.html