kotlin for i in range how to get index value of i

To get the index value of 'i' when using the range in Kotlin, you can use the 'forEachIndexed' function. This function provides the index and value of each element. Here's an example:

val range = 1..5
range.forEachIndexed { index, value ->
    println("Index: $index, Value: $value")
}

In this example, the 'forEachIndexed' function is used to iterate through the range '1..5' and print the index and value of each element.