Extension of while syntax
Terry Reedy
tjreedy at udel.edu
Thu Dec 11 22:00:44 EST 2014
On 12/11/2014 9:21 PM, Nelson Crosby wrote:
> I was thinking a bit about the following pattern:
>
> value = get_some_value()
> while value in undesired_values:
> value = get_some_value()
This is do_while or do_until. In Python, write it as do_until in this form.
while True:
value = get_some_value()
if value not in undesired_values:
break
> I've always hated code that looks like this. Partly due to the repetition,
> but partly also due to the fact that without being able to immediately
> recognise this pattern, it isn't very readable.
The repetitiion is easily eliminated.
> value = get_some_value() while value in undesired_values()
Forget this, or anything like it, as a 'serious' proposal.
--
Terry Jan Reedy
More information about the Python-list
mailing list