for i loop in kotlin code example

Example 1: kotlin for loop

val list = listOf("A", "B", "C")
for (element in list) {
 println(element)
}

Example 2: kotlin simple for loop

val names = listOf("Jack", "John", "Tim")
for(name in names){
	println(name)
}

Example 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

Tags:

Css Example