

In Kotlin, listOf() is used to create a list and we can pass different data types at the same time. The elements in the array are zero-indexed, which means the index of the first element is 0, the. and can produce lots of different sequences of values in the index variable. An array is an ordered collection of values of the same type.

Let’s say you have a collection of fruits, and for each fruit, you want to print its name and index. You can traverse through collection (list, map, set) using the for loop. In Kotlin, for loop is used to iterate through the following because all of them provides iterator. This is so common that Kotlin provides a second loop that captures this. In Kotlin, the for looping construct is used to cycle through an iterable and perform a consistent action on every iteration instance. Iterate through collection using for loopĪ collection usually contains a number of objects of the same type and these objects in the collection are called elements or items. The syntax of for loop in Kotlin is: for (item in collection) ")*/
