In the following example we are iterating though an integer range using for loop. In this guide, we will learn how to use for loop in Kotlin with the help of various examples. Meaning, the range has elements from 25 to 31 in steps of 1, which is of course the default, as we have not mentioned any step value for the range. 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 is used to iterate or cycle though the elements of array, ranges, collections etc. The following Kotlin program demonstrates how to use a for loop to execute a set of statements for each of the element in the range. You can use Kotlin ranges to create a range of data to scan ( 1.10 indicates a range from 1 to. You will learn more about ranges in the next chapter - which will create a range of values. You can traverse through collection (list, map, set) using the for loop. The for loop is now used in the form of in . In Kotlin, the for loop is used to loop through arrays, ranges, and other things that contains a countable number of values.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. There are three ways for creating Range in Kotlin Using (.) operator Using rangeTo () function Using downTo () function (. The syntax of for loop in Kotlin is: for (item in collection) ")*/
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |