kotlin速成之道:loop

```

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)

}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章