For loop in Kotlin is slightly different from java. In Kotlin, for loop is used to iterate through ranges, arrays and maps.

First go through the program given above and understand the flow of for loop in Kotlin.

Range expressions are formed with rangeTo functions that have the operator form, which is complemented by in and !in. Range is defined for any comparable type, but for integral primitive types it has an optimized implementation. Here are some examples of using ranges: