Code to print both index numbers and values in Kotlin?

All QuestionsCategory: KotlinCode to print both index numbers and values in Kotlin?
chetan shidling asked 4 years ago

I need short information.

1 Answers
chetan shidling answered 4 years ago

Here is the code to print both index numbers and values in Kotlin.
 
fun main(args : Array<String>){
var nums = listOf(1,2,3,4)

for((i,e) in nums.withIndex())
{
println(” $i : $e”)
}
}
 
Output:
 
0 : 1
1 : 2
2 : 3
3 : 4