Answers for "kotlin foreach"

2

kotlin foreach

var list = listOf<String>("1", "2", "3")
 
    list.forEach {
        println(it)
    }
Posted by: Guest on July-17-2021
2

kotlin loop

val school = arrayOf("shark", "salmon", "minnow")
for (element in school) {
    print(element + " ")
}
-> shark salmon minnow

for ((index, element) in school.withIndex()) {
    println("Item at $index is $element\n")
}
-> Item at 0 is shark
Item at 1 is salmon
Item at 2 is minnow
Posted by: Guest on June-16-2020
3

kotlin iterate array

val names = listOf("Anne", "Peter", "Jeff")
for (name in names) {
    println(name)
}
Posted by: Guest on May-17-2020

Browse Popular Code Answers by Language