[Python-ideas] For/in/as syntax

Ethan Furman ethan at stoneleaf.us
Fri Mar 3 12:15:47 EST 2017


On 03/03/2017 08:21 AM, Matthias Bussonnier wrote:

>> ##################################################
>> # forloop.break(), to break out of nested loops (or explicitly out of
>> current
>> #loop) - a little like pep-3136's first proposal
>>
>> has_dog_named_rex = False
>> for owner in owners:
>>      for dog in dogs:
>>          if dog.name == "Rex":
>>              has_dog_named_rex = True
>>              break
>>
>>      if has_dog_named_rex:
>>          break
>>
>> # would be equivalent to
>>
>> for owner in owners as owners_loop:
>>      for dog in dogs:  # syntax without "as" is off course still supported
>>          if dog.name == "Rex":
>>              owners_loop.break()
>
> See my above proposal, you would still need to break the inner loop
> here as well. So i'm guessing you miss a `break` afrer owner_loop.break() ?

No, he's not -- part of implementing this change includes not needing to specify the inner breaks.

--
~Ethan~



More information about the Python-ideas mailing list