Technically, I guess we are both right. I am thinking like a compiler implementer.
Looking at this code:
Code:
100 gosub 1000
200 gosub 2000
300 end
1000 for i = 1 to 2
1100 goto 3000
2000 for i = 7 to 6 step -1
2100 goto 3000
3000 print i
3100 next i
3200 return
---
My way:
Activation record contains:
Code:
identity of loop variable
address of top of loop
address of loop exit
init part of FOR statement does:
Code:
assign starting value to loop variable
create activation record
store loop variable identity in activation record
store address of top of loop
The iterate part is different depending on whether the loop counts up or down.
iterate part of an up counting FOR statement does:
Code:
add step to loop variable
if loop variable > terminating value:
discard activation record
goto loop exit
iterate part of a down counting FOR statement does:
Code:
add step to loop variable
if loop variable < terminating value:
discard activation record
goto loop exit
NEXT statement does:
Code:
verify loop variable identity
raise error if not matching
store loop exit address in activation record
goto top of loop
---
Your way:
Activation record contains:
Code:
identity of loop variable
address of top of loop
termination value
step value
init part of FOR statement does:
Code:
assign starting value to loop variable
create activation record
store loop variable identity in activation record
store address of top of loop
store termination value in activation record
store step value in activation record
iterate part of FOR statement does:
Code:
nothing
NEXT statement does:
Code:
verify loop variable identity
raise error if not matching
add step to loop variable
if step is positive:
if loop variable <= termination value:
goto top of loop
else:
if loop variable >= termination value:
goto top of loop
discard activation record
---
Added complication: some BASIC interpreters allow leaving off the loop variable from the NEXT statement. For your way, NEXT would have to use indirection to get to the loop variable.
Further consideration, my way allows for easy optimization when the loop variable deals with integer instead of floating point values.