Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For loops with type byte (*solved*)
#2
britlion Wrote:
Code:
dim c,b as byte


FOR c=1 TO 175
FOR b=1 TO 250
  PLOT b,c
NEXT b
NEXT c

Doesn't seem to work as expected. If I make it a uinteger, it works perfectly.
You must use ubyte (Unsigned Byte), since byte type is signed, and in the above lines, you have an overflow:
ubyte 175 is -85 byte => the FOR loop is skipped. In the future, the compiler might issue an overflow warning in these cases to warn you about this.
Quote:1> Would for/next loops with byte be faster? (I'm following the principle of smaller=faster)
It should be. Z80 is an 8 bit machine and the FOR is done with 8bit values when using bytes.
If you can understand Z80 ASM (I guess you do Wink) compile your program with --asm and have a look at the output.


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)