Non-obvious name bindings
kseehof at neuralintegrator.com
Wed Nov 14 23:40:26 CET 2001
Jeff Shannon wrote:
> . . .
> If I'm reading the bug report right, then it *is* expected behavior that
> comp variables are function-local variables, not true "temporary"
> C++ (IIRC) treats loop indices as being limited to the scope of the loop
> and invalid once the loop ends. Python, however, has a much simpler
> scheme, and doesn't use a separate scope for loops (and list comps are
> syntax sugar for a for-loop).
> . . .
> Jeff Shannon
> Credit International
Actually, the index has the scope that contains the 'for' statement, so
it does persist after the loop.
int main(int argc, char* argv)
for (int i=0; i<10; i++)
printf("%d ", i);
printf("\n\n i = %d", i);
0 1 2 3 4 5 6 7 8 9
i = 9
More information about the Python-list