Forum
for/next/step - did i find a bug? - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16)
+---- Thread: for/next/step - did i find a bug? (/showthread.php?tid=396)



for/next/step - did i find a bug? - nitrofurano - 11-03-2011

i don't know if this is a bug, or if i'm defining variable kind wrongly ('j' is not stopping at '0') - thanks in advance! Smile

Code:
border 0:cls
dim i,j as uinteger
for i=0 to 6143 step 3
  poke 16384+0+i,128+16+2
  poke 16384+1+i,64+8+1
  poke 16384+2+i,32+4
  next i
lp01:
for j=16384 to 0 step -32
  print at 0,0;j;" "
  pause 1
  for i=0 to 767
    poke 16384+6144+i,peek(i+j) band 127
    next i
  next j
goto lp01



Re: for/next/step - did i find a bug? - boriel - 11-03-2011

This has been discussed many times.
You're defining j variable as Uinteger, so a FOR from 16384 DOWNTO 0 will stop when the j variable passes beyond 0, thus negative. This will never happen, because j is always positive (UInteger), so it overflows from 0 to (65535 - 31) and never stops


Re: for/next/step - did i find a bug? - boriel - 11-07-2011

Did you try changing the value type? :roll:


Re: for/next/step - did i find a bug? - nitrofurano - 11-07-2011

boriel Wrote:Did you try changing the value type? :roll:
nope, i kept uinteger, because i were only using values from 0 to 65535 - btw, i got that overflow issue you told, and this situation is focusing me on try different aproaches when coding - thanks