Answers for "kotlin for i in range how to get index value of i"

7

kotlin simple for loop

val names = listOf("Jack", "John", "Tim")
for(name in names){
	println(name)
}
Posted by: Guest on February-18-2020
3

kotlin loop

var bubbles = 0
while (bubbles < 50) {
    bubbles++
}
println("$bubbles bubbles in the water\n")

do {
    bubbles--
} while (bubbles > 50)
println("$bubbles bubbles in the water\n")

repeat(2) {
     println("A fish is swimming")
}
-> 50 bubbles in the water
49 bubbles in the water
A fish is swimmingA fish is swimming
Posted by: Guest on June-16-2020
0

kotlin for i in range how to get index value of i

val mylist = listOf("karate","taekwondo","sumo","boxing")
for ((index, value) in mylist.withIndex()) {
    println("the element at $index is $value")
}
Posted by: Guest on March-11-2021

Browse Popular Code Answers by Language