What could be an alternate way to print the cells of a table other than using a nested loop.
for(i in 1..2){
for(j in 1..2){
println("$i,$j")
}
}
Any approach using Pairs?
What could be an alternate way to print the cells of a table other than using a nested loop.
for(i in 1..2){
for(j in 1..2){
println("$i,$j")
}
}
Any approach using Pairs?
You can use map/flatMap to convert the ranges to list of Pairs
val pairs = (1..2).flatMap { i -> (1..2).map { j -> i to j } }
pairs.forEach { println("${it.first},${it.second} ") }