cYn cYn - 6 months ago 48
Scala Question

Increment for-loop by 2 in Scala

How do I increment the loop by 2 as equivalent to this in Java:

for (int i = 0; i < max; i+=2)

Right now in Scala I have:

for (a <- 0 to max)

For a fact
will always be even. I don't know how to increment the counter to 2 in each loop.


Try for (a <- 0 until max by 2)