kotlin indexed for loop code example
Example 1: for loop kotlin
val array = arrayOf(1, 3, 9)
for (item in array) {
}
for (index in 0..array.size - 1) {
}
for (index in 0 untill array.size) {
}
for (index in array.indices) {
}
Example 2: 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