[Kotlin] for loop

fun main() {
    val list = listOf("Java", "Kotlin", "Python")
    
    for (element in list) {
        println(element)
    }
    
    for ((index, value) in list.withIndex()) {
        println("Elmenet at $index is $value")
    }
    /*
     * Elmenet at 0 is Java
       Elmenet at 1 is Kotlin
       Elmenet at 2 is Python
    */
}

 

posted @ 2020-10-11 20:01  Zhentiw  阅读(119)  评论(0编辑  收藏  举报