For example, a horizontal pass followed by a vertical pass of pixels in an image, both encompassing the same code - only the loop order is different:
Code: Select all
;Horizontal pass
For y = 1 to height
For x = 1 to width
;process pixel (x,y)
Next x
Next y
;Vertical pass
For x = 1 to width
For y = 1 to height
;process pixel (x,y)
Next y
Next x
While I was typing that example i realized perhaps simply "Swap(xcopy, ycopy)" might be one simple solution but im still curious about other options, and i'm thinking that might not actually work unless both width and height are the same size.
Of course another option is to have the two copies of the loop, just like in the previous example, and call a single ProcessPixel procedure, but then you don't easily have access to all the internal variables of that procedure without sending them all over as parameters, not always ideal!
i had came up with the following also but it's uh... yeah, lol
Code: Select all
swapped=0
xmax = 2 ;x = 0 to 2
ymax = 3 ;y = 0 to 3
Repeat
Debug "x="+Str(x) + " y="+Str(y)
If swapped
x + 1
If x > xmax
x = 0: y + 1
If y > ymax: Break: EndIf
EndIf
Else
y + 1
If y > ymax
y = 0: x + 1
If x > xmax: Break: EndIf
EndIf
EndIf
ForEver