zxbasic icon indicating copy to clipboard operation
zxbasic copied to clipboard

FOR LOOP repeating

Open em00k opened this issue 7 years ago • 4 comments

I find this for loop repeats, only happens if to is set to 255

for x = 0 to 255 
	print at 0,0;x
	pause 1
next x 
pause 0

em00k avatar Oct 09 '18 21:10 em00k

That's to be expected if x is of type UByte. By default, if you don't DIM x it will assign the shortest / narrowest type (UByte in this case).

FOR loops like the above means the loop must enter when x = 255, and stop when x = 256. Since x is of type UByte, it will never reach 256. Hence the infinite loop.

EDIT: I repost my comment because the previous response has been lost :(

jmrodriguez-clv avatar Apr 04 '19 08:04 jmrodriguez-clv

Sorry ignore my last post on this.

em00k avatar Jan 19 '21 12:01 em00k