Scala Question Regarding readLine

I have stumbled upon a weirdness regarding the behavior of readLine in Scala (at least with my current basic understanding of the language).

The following snippet is supposed to read three times a line from standard in. But it reads 3 times the same line (the first).

[code]
(1 to 3) foreach {
 val line = Console.readLine
 i => println(line)
}
[/code]

while the following snippet (very similar) behaves as expected (reading the three first line from stdin):

[code]
(1 to 3) foreach {
 i => println(Console.readLine)
}
[/code]

Any idea why?

Like what you read? Give Patrick Jayet a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.