The for loop in Kotlin iterates over any object that provides an iterator. It is similar to the for..in loop in Ruby. The loop has this syntax:
for (obj in collection) { … }
The block in the for loop is not necessary if only a single statement exists in the loop. A collection is a type of structure that provides an iterator. Consider the following program:
val numSet = arrayOf(1, 563, 23)for (number in numSet) { println(number)}
Each value in the numSet array is iterated upon by the loop and assigned to the variable number. The number is then printed to the standard system output.