Breaking Out
Bengt Richter
bokr at oz.net
Fri Aug 23 22:32:45 EDT 2002
On Fri, 23 Aug 2002 23:03:04 +0100, "James Kew" <james.kew at btinternet.com> wrote:
>"Bradley D. Larson" <blarson at crary.com> wrote in message
>news:mailman.1030131895.10485.python-list at python.org...
>
>> I believe a cleaner method is:
>>
>> while x = y:
^-- s/b '=='
>> blah
>> blah
>> blah
>> if break_now:
>> break
>> blah
>> blah
>> blah
>> if break_now:
>> break
>> blah
>> blah
>> blah
>> [...]
>> break # dont forget the last break!
>
>That makes a conditional look like a loop -- not terribly expressive of
>intent.
>
>"Skip to the end" and "I WANT OUT" suggest throwing an exception to me...
>
You could avoid indentation by specifying the full condition for each segment, e.g.,
xycond = x==y # in case blahs change x or y
if xycond:
blah
blah
blah
if xycond and not break_now:
blah
blah
blah
if xycond and not break_now_2:
blah
blah
blah
[...]
Not wonderful, but ...
Regards,
Bengt Richter
More information about the Python-list
mailing list