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...@python.org] On Behalf Of Ben Finney >Sent: Thursday, December 11, 2014 6:38 PM >To: python-list@python.org >Subject: Re: Extension of while syntax > >Nelson Crosby <n...@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 -- https://mail.python.org/mailman/listinfo/python-list