AluminumLua icon indicating copy to clipboard operation
AluminumLua copied to clipboard

else statement variable context

Open leslie-linden opened this issue 12 years ago • 0 comments

Hi. I've noticed an issue with variable contexts in "else" statements. The following code:

bar = 0 function foo() print "bar is " .. bar if bar > 0 then bar = 0 else bar = bar + 1 end end foo() foo() foo() foo()

Has the following output: bar is 0 bar is 1 bar is 0 bar is 2

The "else" block seems to have its own local context for the "bar" variable which is remembered each time the block is executed. I wasn't able to figure out any workaround to this issue in the general case, although the above code can be edited to make the problem go away by not using an else statement.

Thanks again.

leslie-linden avatar Nov 01 '13 19:11 leslie-linden