Scala FAQ: Can you share some examples of the Scala for loop syntax?
Sure. I'm going to start with a comparison to Java for loops, because that's what I was just thinking about.
In Java you might write a for loop with a counter like this:
for (int i = 0; i < 10; i++) {
System.out.println(i);
}
The equivalent for loop in Scala looks like this:
for (i <- 1 to 10) {
println(i)
}
(The use of parentheses isn’t necessary in either example, but most for loops will be longer.)