kotlin for
snippet in kotlin

Kotlin when

user2724

val x = 3
when(x) {
    3 -> println("yes")
    8 -> println("no")
    else -> println("maybe")
}
// when can also be used as an expression!
val y = when(x) {
    3 -> "yes"
    8 -> "no"
    else -> "maybe"
}
println(y) // "yes"

kotlin simple for loop

user8914

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

for loop kotlin

user5821

val array = arrayOf(1, 3, 9)
for (item in array) {
    //loops items
}
for (index in 0..array.size - 1) {
	//loops all indices
}
for (index in 0 untill array.size) {
    //loops all indices
}
for (index in array.indices) {
    //loops all indices (performs just as well as two examples above)
}

for loop kotlin

user9105

for (x in 0..10) println(x)

kotlin iterate array

user4228

val names = listOf("Anne", "Peter", "Jeff")
for (name in names) {
    println(name)
}

kotlin for

user350

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