If a variable is defined in a for, while, or range loop which does not run because (a) the list is empty (b) the condition is initial false, or (c) the integer is less than or equal to zero, it will be transformed upon leaving the (un-run) loop and consequently defined. This is because STransforms are added as SStage(entry, loop, exit), and the entry and exit blocks, which contain the STransforms, run regardless of the condition. This can be fixed by refactoring the While, Range, and For types to include the entry and exit conditions, and only running them if the condition is true/valid. A basic example is:
for i in []:
x = 4
print(x)
print(x)
i = 0
while i > 0:
x = 4
print(x)
print(x)
If a variable is defined in a for, while, or range loop which does not run because (a) the list is empty (b) the condition is initial false, or (c) the integer is less than or equal to zero, it will be transformed upon leaving the (un-run) loop and consequently defined. This is because STransforms are added as SStage(entry, loop, exit), and the entry and exit blocks, which contain the STransforms, run regardless of the condition. This can be fixed by refactoring the While, Range, and For types to include the entry and exit conditions, and only running them if the condition is true/valid. A basic example is: