Examveda

The code below shows a typical way to show both index and value in many languages, including Kotlin. Which line of code shows a way to get both index and value more idiomatically?
var ndx = 0;
for (value in 1..5){
  println("$ndx - $value")
  ndx++
}

A. for( (ndx, value) in (1..20).withIndex() ){

B. for( (ndx, value) in (1..20).pair() ){

C. for( Pair(ndx, value) in 1..20 ){

D. for( (ndx, value) in *(1..20) ){

Answer: Option A


This Question Belongs to Computer Science >> Kotlin Program

Join The Discussion

Related Questions on Kotlin Program

What is Kotlin?

A. A new version of Java.

B. A JavaScript framework.

C. A statically-typed programming language for the JVM, Android, and browser.

D. A database management system.