Tag Archives: scala

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).

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

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

(1 to 3) foreach {
  i => println(Console.readLine)
}

Any idea why?