|
|
|
|
|
by ufo
3439 days ago
|
|
In Lua it prints 1,2,3,4. It has to do with each loop iteration behaving as if it declared a different variable instead of sharing the same variable across the loop. Anyway, the problem they were talking about is clearer when you are closing over stuff that other than the loop variable: fns = []
for n in [1,2,3,4]:
x = n*10
def fn():
print(x)
fns.append(fn)
|
|