cYn cYn - 1 year ago 113
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download