Earlier quoted context omitted.
So your first example was clearly a bad example. This was a better example. But even so, this is a lousy example since x is already defined at the top. So the for loop could theoretically use the defined x already. I think what you're looking for is something akin to the following in C: int x = 5; for (int x=0; x But I would argue that this is terrible C code since the inner x shadows the outer scope leading to confu…
No, the first example illustrates the fundamental problem that all iterations of the loop share the same scope rather than a new one each. In your example, the variable `x` is also shared with all iterations of the loop. Rather, it is more so as so in C , like syntax what is the common approach: while(1) { int x = next(iterator) if(STOPITER) { break } /* code that uses x */ } Every iteration of the loop receives a br…
In that case I would prefer to be explicit that the closure "wraps" a new instance of the variable rather than relying upon implicit language behavior to guarantee the scope is correct.
As python says in "import this": "Explicit is better than implicit."