Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compiuter PlotChat
#8
britlion Wrote:This seems a little awkward:

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...)
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:
DIM i as Ubyte = 0

DO
...
i = i + 1
LOOP UNTIL i = 0 : REM YES, with overflow, 0 == 256 (mod 256)
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)