You can use Kotlin ranges to create a range of data to scan ( 1.10 indicates a range from 1 to.
In Kotlin, listOf() is used to create a list and we can pass different data types at the same time. The for loop is now used in the form ofA second Variant: ilya.gorbunov June 8, 2017, 11:16pm 2 myList is a mutable property and it can be changed after the null check (as the second message clearly tells), that’s why compiler doesn’t allow smart-cast in the subsequent usages. You can traverse through collection (list, map, set) using the for loop. Unlike Java and other programming languages, there is no traditional for loop in Kotlin. For-loop range must have an ‘iterator ()’ method. Kotlin provides a collection of elements with a start and end point. The idea is to create a range of array indices and. 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. In Kotlin, you can easily create ranges of values using the rangeTo() function and its operator form. The syntax of for loop in Kotlin is: for (item in collection) ")*/