Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables defined in for, while, or range loops which do not run are defined in the outside scope #8

Open
jacobaustin123 opened this issue Jan 12, 2019 · 0 comments

Comments

@jacobaustin123
Copy link
Owner

jacobaustin123 commented Jan 12, 2019

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant