breaking out of outer loops

Steven Bethard steven.bethard at gmail.com
Wed Jan 30 01:56:42 CET 2008


Jeremy Sanders wrote:
> noemailplease0001 at gmail.com wrote:
> 
>> Any elegant way of breaking out of the outer for loop than below, I
>> seem to have come across something, but it escapes me
>>
>> for i in outerLoop:
>>    for j in innerLoop:
>>        if condition:
>>           break
>>    else:
>>        continue
>>     break
> 
> Perhaps Python needs a "continue N" or a "break N" statement :-)
> 
> for i in outerLoop:
>   for j in innerLoop:
>      if condition:
>         break 2
> 
> Seeing as we can't have a goto :-)

Not true!  You just have to import it:

     http://entrian.com/goto/

STeVe



More information about the Python-list mailing list