Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A For-Next bug in 1.2.8-s682
#2
Darkstar Wrote:This works:

Code:
For i = AttrAddress to AttrAddress + NumberOfCells - 1
  Poke i, AttrColor
Next i

This does not:

Code:
For AttrAddress = AttrAddress to AttrAddress + NumberOfCells - 1
  Poke AttrAddress, AttrColor
Next AttrAddress

This would work in other dialects.

Thanks,

Darkstar
This is related to the ZX Basic to have "Dynamic" evaluation on each pass. In your loop:
Code:
For i = i to i + N - 1
  Poke i, AttrColor
Next i
the expression i + N - 1 is evaluated *on each pass* (like in C). On most BASIC dialects (including Sinclair BASIC), that expression is only evaluated the 1st time (on entering the loop). On each pass, i + N - 1 is recalculated, and since it's always increasing, the loop will eventually overflow (or run forever).
At the moment, the only way to fix this is:
Code:
LET z = i + N - 1
For i = i to z
  Poke i, AttrColor
Next i
Can you check this?

Which produces the expected behavior. I'm thinking in fixing this in an more efficient manner, so the user can choose dynamic or static FOR loops with a #pragma directive, and let FOR to be static by default for compatibility's sake. What do you think?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)