Extension of while syntax

Clayton Kirkwood crk at godblessthe.us
Thu Dec 11 21:59:20 EST 2014


I would prefer:
while value = initial_value in undesired_values:
        value = get_some_value()

Seems I've seen something like this before, C, Perl?

Clayton


>-----Original Message-----
>From: Python-list [mailto:python-list-
>bounces+crk=godblessthe.us at python.org] On Behalf Of Ben Finney
>Sent: Thursday, December 11, 2014 6:38 PM
>To: python-list at python.org
>Subject: Re: Extension of while syntax
>
>Nelson Crosby <nc at sourcecomb.com> writes:
>
>> I was thinking a bit about the following pattern:
>>
>> value = get_some_value()
>> while value in undesired_values:
>>     value = get_some_value()
>
>I think that's an anti-pattern (because of the repetition, as you say).
>
>An improvement::
>
>    value = some_default_value_such_as_None
>    while value in undesired_values:
>        value = get_some_value()
>
>More common and generally useful::
>
>    while True:
>        value = get_some_value()
>        if value not in undesired_values:
>            break
>
>> What are other's thoughts on this?
>
>I think there are already clean ways to deal with this in common use.
>
><URL:https://wiki.python.org/moin/WhileLoop>
><URL:https://docs.python.org/3/tutorial/controlflow.html#break-and-
>continue-statements-and-else-clauses-on-loops>
>
>--
> \       “… one of the main causes of the fall of the Roman Empire was |
>  `\        that, lacking zero, they had no way to indicate successful |
>_o__)                  termination of their C programs.” —Robert Firth |
>Ben Finney
>
>--
>https://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list