africanpolew.blogg.se

Kotlin for loop range
Kotlin for loop range








kotlin for loop range

If we would like to exclude the last value, we should use until: for (x in 0 until 5) Let’s iterate through such a range: for (x in 0.5)Īs the output, we should see the following: 012345Īs you can see, our range contains values from 0 to 5 (inclusive). Kotlin allows us to easily declare ranges using an operator form (.) of the rangeTo() function. Let’s see the following examples to get a better understanding of the topic. Kotlin’s for loops are pretty similar to Python’s and allow the user to iterate through everything that is iterable (has an iterator()). There is no traditional for loop in Kotlin (like you could use in Java or other programming languages). If you have any prior experience with other programming languages, these concepts may seem trivial for you, but I still believe, that it is worthy to spend some time to remind the core concepts.

kotlin for loop range

We will learn, how to use for-loop, forEach, while, break and continue in our code.

kotlin for loop range

In this article, we will cover the basics of the Kotlin programming language- loops. Also, I can now open the secret and announce that video tutorials are coming soon 🙂 I hope, you really enjoy these guides and I would be more than happy if you could share with me your thoughts (for example, by using the contact form). I am doing my best to provide more and more, better quality content from week to week. In the beginning, I wanted to thank you so much for all the feedback, you’ve provided so far. Hello dear readers and welcome to my 13th article.










Kotlin for loop range