You have several errors in it. I don't know about speed, propably not faster. It can have some modifications which still won't help much. Mod itself on every index makes it heavier than simple for-loop:
Code:
y:=-1; // important to initialize y, and know that y gets +1 on first round
for i:=0 to Map_width * map_height -1 do // added -1, because it starts from 0
begin
x:=i mod Map_width;
if x=0 then y:=y+1; // mod Width, not height, and then we can re-use x
// do_something_with_xy
//i:=i+1; // Don't modify for-loop variable
end;
This version however might be faster than the for-loop, or at least equal:
Code:
x:=0; y:=0;
for i:=0 to Map_width * map_height -1 do begin
// do_something_with_xy
x:=x+1;
if x=Map_width then begin
x:=0;
y:=y+1;
end;
end;
Bookmarks