Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serious FOR bug in latest dev build s1964
#15
(01-21-2021, 09:44 PM)smok Wrote: I ran across this bug as well and I'm a bit puzzled.

How do you plot pixels across ZX Spectrum screen using UBYTE?

None of the build-in loops can help, I end up with solution like this (which is almost as fast as for .. next loop)


Code:
DIM x as UBYTE
do
  plot x,30
  if x = 255 then exit do
  x = x + 1
loop

When I use:


Code:
for x=0 to 254
  print at 0,0;x
next x
print at 1,0;x

I see 254 and printed 255 below, but I can't be in the loop for 255 because it will be overflown.

Or maybe I'm missing something?

That's it.
You can do FOR i = 0 to 255 as Ubyte, because it will overflow and never reach 255. A warning will be issued in the future when these patterns are catched. The reason is for how FOR semantics is implemented. The loop will stop *after* the iterator variable goes beyond the limit, which will never happen in this case.

Use UInteger for plot coords. Indeed Draw x y are UIntegers (their value ranges form -255 to +255).

An alternative approach in your case is:
Code:
DIM x as UByte
x = 0
DO
    PRINT AT 0, 0; x;
    LET x = x + 1
LOOP UNTIL x = 0

The loop you write is also ok, but look it starts to get "cumbersome". You got it. That's the problem: The FOR once it reaches the end, needs to increment and execute the body only if it's equal or lower. There's another solution I'm thinking of, but in the meantime please use the LOOP approach.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)