I will show you the examples of for loop in Kotlin with range, array, and string etc. For example, a range, array, string, etc. In Kotlin, listOf() is used to create a list and we can pass different data types at the same time. The for loop in Kotlin can be used to iterate through anything that provides an iterator. You can traverse through collection (list, map, set) using the for loop. However, there are many more ways through which you can iterate through Range. A range defines a closed interval in the mathematical sense: it is defined by its two endpoint values which are both included in the range. 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. We have given an example to show how can you traverse through Range in Kotlin. The for loop in Kotlin can be used to iterate through anything that provides an iterator. The syntax of for loop in Kotlin is: for (item in collection) ")*/ According to the documentation for ranges: Floating point numbers ( Double, Float) do not define their rangeTo operator, and the one provided by the standard library for generic Comparable types is used instead: public operator fun T.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |