03-30-2011, 10:26 AM
britlion Wrote:Boriel,Certainly, if they're complex expressions. Static ones are just like using a temporary variable to store them. The problem is... how to compile them? :roll: Using the stack is a problem if the user jumps out the loop using GOTO. Using a static place is also problematic (and a waste of memory). The most straightforward solution is to use a hidden variable and implement it as shown above. This would imply FOR-NEXT variables will take twice the space of a normal variable, anyway (Sinclair BASIC also makes a distinction between normal variables and FOR-NEXT ones, not only in their length name, but also in their internal implementation).
I think that's probably the right choice, since most basic dialects use it. You can always do a dynamic expression with a do...until (x) style loop, where it feels more natural to have an expression evaluated each loop, I think.
Will static evaluation speed up for loops?