Loops/Increment loop index within loop body: Difference between revisions

Content added Content deleted
Line 1,540:
Haxe's for-loop does allow the index to be modified in the body of the loop, so a while-loop is used instead.
<lang haxe>using StringTools;
import haxe.Int64;
 
class PrimeNumberLoops {
private static var limit = 42;
static function isPrime(i:haxe.Int64):Bool {
if (i == 2 || i == 3) {
return true;
Line 1,561 ⟶ 1,562:
 
static function main() {
var i:haxe.Int64 = 42;
var n:haxe.Int64 = 0;
while (n < limit) {
if (isPrime(i)) {
n++;
Sys.println('n ${haxe.Int64.toStr(n).lpad(' ', 2)} ' +
'= ${haxe.Int64.toStr(i).lpad(' ', 19)}');
i += i;
continue;