Like any other programming languages, Kotlin uses the concept of loop. Loops are mainly used to repeat a specific task. For Example, if we want to print numbers from 1 to 20, instead of writing a print statement 20 times, we can execute it through loops. Loops reduce the number of rows in the program and improve reliability. Loops are control flow structures that control the flow of the program within the loops.
For loop in Kotlin repeats itself through whatever an iterator operator provides. Unlike in Java and other languages, there is no traditional loop in Kotlin. In Kotlin, for loop is used to repeat sequences, arrays, and maps (anything provided by the iterator).
Kotlin has three types of loops:
|