Stuck in a loop

BlitzMax Forums/BlitzMax Beginners Area/Stuck in a loop

Would some kind person be able to explain to me why the following code fails:

Global a:Int, b:Int, recheck:Int=0, finish:Int=0

While finish=0
	recheck=0

		For loop=0 To num-2
		a=tiles[loop].tile_layer_pos
		b=tiles[loop+1].tile_layer_pos

			If b>a Then
				a=tile_order[loop]
				b=tile_order[loop+1]
				tile_order[loop]=b; tile_order[loop+1]=a
				recheck=1;
			EndIf

		Next
		
		If recheck=0 Then
		 finish=1
		EndIf
Wend


This is assuming that NUM=63, what it should be doing is checking - then switching, if there's no more checks quit out of the routine.

But its stuck in its own loop :(

Only reason I see here is that you take a,b for comparision from tiles[] but you change the array tile_order.

Until you either compare with tile_order or change tiles[] it can't end with this structure as tiles is unchanged on each recheck but tile_order gets swapped all the time.

DOOOHHH !!!!

Thanks for pointing that out :)