

We will study Kotlin Ranges in a separate chapter, for now you should know that Kotlin Ranges provide iterator, so we can iterate through a range using for loop.įollowing is an example where the loop iterates through the range and prints individual item. The syntax of the Kotlin for loop is as follows: Kotlin does not provide a conventional for loop which is available in C, C++ and Java etc. Kotlin for loop is equivalent to the foreach loop in languages like C#. that contains a countable number of values, for example arrays, ranges, maps or any other collection available in Kotlin. Kotlin for loop iterates through anything that provides an iterator ie. Kotlin supports various types of loops and in this chapter we are going to learn Kotlin for loop. Actually, Loops are used in programming to repeat a specific block of code until certain condition is met. What about if you need to print the same sentence one thousand times? This is where we need to use loops to simplify the programming job. You can do it by using print statement 20 times.

Imagine a situation when you need to print a sentence 20 times on your screen.
