A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-May/064673.html below:

[Python-Dev] elimination of scope bleeding of iteration variables

[Python-Dev] elimination of scope bleeding of iteration variables [Python-Dev] elimination of scope bleeding of iteration variablesGreg Ewing greg.ewing at canterbury.ac.nz
Mon May 1 11:34:17 CEST 2006
Nick Coghlan wrote:
> However, the scoping of for loop 
> variables won't change, as the current behaviour is essential for search loops 
> that use a break statement to terminate the loop when the item is found. 

It occurs to me that there's a middle ground here:
leave the loop variable scope alone, but make it
an error to use the same variable in two different
loops at the same time.

e.g.

   for x in stuff:
     if its_what_were_looking_for(x):
       break
   snarfle(x)
   for x in otherstuff:
     dosomethingelse(x)

would be fine, but

   for x in stuff:
     for x in otherstuff:
       dosomethingelse(x)

would be a SyntaxError because the inner loop
is trying to use x while it's still in use by the
outer loop.

--
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4