In a book on Scala programming I came around this example. They say that this example of imperative code
def printArgs(args: Array[String]): Unit = {
var i = 0
while (i < args.length) {
println(args(i))
i += 1
}
}
Can be "translated" into functional style like that:
def printArgs(args: Array[String]): Unit = {
for (arg <args)
println(arg)
}
But to me these two codes are not absolutelly identical, the second one completelly missing variable "i". And so if I want to print it along with value of string I cannot do it in the second example, or can I? How?