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++
}
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
Related Questions on Kotlin Program
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.
Which platform does Kotlin primarily target?
A. Python Bytecode
B. JavaScript
C. JVM (Java Virtual Machine) Bytecode
D. PHP

Join The Discussion