There are two ways for simple integer loops:
for (i <- 1 to 1000000) { ... }
for
(i <- 1 to 1000000) { ... }
or
var i = 1; while (i <= 1000000){ ...; i += 1 }
var
i = 1; while (i <= 1000000){ ...; i += 1 }
Both are fine, but in the current implementation the second one should be more efficient.