isPrime works but UnBoundLocalError when mapping on list

Andreas Tawn andreas.tawn at ubisoft.com
Wed Jul 16 08:24:19 EDT 2008


 
> Andreas Tawn wrote:
> > Terry Reedy wrote:
> >> Wrong.
> > Thank you.
> > 
> >> For loop variables continue after the loop exits.  This is 
> >> intentional.
> > I never knew that and I can't find reference to it in the docs. 
> 
> Interesting starting point. It never occurred to me
> that they might not. (So I didn't look for anything
> in the docs when they did :) ).
> 
> TJG

I don't have experience of too many other languages, but in C++ (and I
guess C)...

for (int i=0; i<10; ++i)
{
    doStuff(i);
}

doStuff(i); // Error

int i;

for (i=0; i<10;++i)
{
    doStuff(i);
}

doStuff(i); // No error

That's the behaviour I was expecting.

Is the Python behaviour just a happy side effect of the target list
assignment or specific design decision?

Cheers,

Drea



More information about the Python-list mailing list