DEF F DIM I FOR I=0TO 10 DIM A=I?A NEXT I END FIn this code, the variable A is dimensioned several times in the FOR loop. From experience I know that dimensioning a variable more than once leads to a duplicate variable error. Upon inspection, dimensioning it again seems to do absolutely nothing to the value of the variable. Why does this code work anyway?
Why does this code work?
Root / Programming Questions / [.]
MZ952Created:
A duplicate definition only happens when you actually have VAR/DIM with the same variable twice in your code:DEF F DIM I FOR I=0TO 10 DIM A=I?A NEXT I END FIn this code, the variable A is dimensioned several times in the FOR loop. From experience I know that dimensioning a variable more than once leads to a duplicate variable error. Upon inspection, dimensioning it again seems to do absolutely nothing to the value of the variable. Why does this code work anyway?
VAR A VAR Anot
WHILE 1 VAR A '<- there's only 1 VAR in the program WENDBasically, it ignores when the VAR is executed, and all that matters is the location in the code:
GOTO @SKIP VAR A @SKIP A=1 'still worksIf you use = in VAR, that will only run when VAR itself runs. (VAR A=1 is the same as VAR A:A=1, basically)