06-21-2010, 07:22 AM
britlion Wrote:This seems a little awkward:DO...LOOP is the same or faster, because FOR ... NEXT is a more complex loop instruction. Also, if LAST value is 255, you can use DO ... LOOP with a byte counter to avoid overflow, whilst FOR will loop forever:
Code:do
...code...
w=w+3
loop until w=200
Is that some optimization or better than:
?Code:FOR W=0 to 200 step 3
NEXT W
Right now I don't know which one is faster, but my gut tells me a for/next loop ought to be - it's designed to have a loop counter. Boriel recently did some optimizations on FOR/NEXT as well, shaving a few clock cycles.
I also have a weird feeling that asking it to stop when W=200 might be a long wait, since 200 doesn't divide evenly by three. (That is, if you keep adding threes, you get 195,198,201,204... - not W=200 until it's looped right around the byte count...)
Code:
DIM i as Ubyte = 0
DO
...
i = i + 1
LOOP UNTIL i = 0 : REM YES, with overflow, 0 == 256 (mod 256)