dmsc / fastbasic

FastBasic - Fast BASIC interpreter for the Atari 8-bit computers
GNU General Public License v2.0
139 stars 20 forks source link

Strange for loop #53

Closed ukcroupier closed 2 years ago

ukcroupier commented 2 years ago

Had something happen that I wasn't expecting,

i=0 for i=i+1 to i+5 ?i;","; next

I was expecting 1,2,3,4,5, but got 1,2,3,4,5,6,

Clearly i is incrementing before getting to 'to i+5' but this isn't how I'd expect this to work (Atari BASIC does it how I would expect)

Not a big problem but though I'd mention it :)

dmsc commented 2 years ago

Hi!

Had something happen that I wasn't expecting,

i=0 for i=i+1 to i+5 ?i;","; next

I was expecting 1,2,3,4,5, but got 1,2,3,4,5,6,

Clearly i is incrementing before getting to 'to i+5' but this isn't how I'd expect this to work (Atari BASIC does it how I would expect)

Yes. FastBasic transforms the above code into:

  I = I + 1
  for_limit = I + 5
  for_step = 1
  WHILE I < for_limit
    ? I;",";
    I = I + for_step
  WEND

BUT, Atari BASIC and Turbo BASIC XL both do the same, they first assign the new value to the variable and then evaluate the FOR limit and step, just test your code, will print 1,2,3,4,5,6.

Have Fun!

ukcroupier commented 2 years ago

Sorry, you're right. Atari BASIC does do it the same way, I must have miss coded my test.

Thanks for your time.

dmsc commented 2 years ago

No problem, Have Fun!