In this article we will learn about some of the frequently asked Kotlin programming questions in technical like “kotlin for i in range how to get index value of i” Code Answer’s. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error or stack handling on kotlin was simple and easy. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in Kotlin. Below are some solution about “kotlin for i in range how to get index value of i” Code Answer’s.
kotlin simple for loop
xxxxxxxxxx
1
val names = listOf("Jack", "John", "Tim")
2
for(name in names){
3
println(name)
4
}
kotlin loop
xxxxxxxxxx
1
var bubbles = 0
2
while (bubbles < 50) {
3
bubbles++
4
}
5
println("$bubbles bubbles in the watern")
6
7
do {
8
bubbles--
9
} while (bubbles > 50)
10
println("$bubbles bubbles in the watern")
11
12
repeat(2) {
13
println("A fish is swimming")
14
}
15
-> 50 bubbles in the water
16
49 bubbles in the water
17
A fish is swimmingA fish is swimming
kotlin for i in range how to get index value of i
xxxxxxxxxx
1
val mylist = listOf("karate","taekwondo","sumo","boxing")
2
for ((index, value) in mylist.withIndex()) {
3
println("the element at $index is $value")
4
}