Extension of while syntax

cl at isbd.net cl at isbd.net
Fri Dec 12 04:09:14 EST 2014


Marko Rauhamaa <marko at pacujo.net> wrote:
> Chris Angelico <rosuav at gmail.com>:
> 
> > You could deduplicate it by shifting the condition:
> >
> > while True:
> >     value = get_some_value()
> >     if value not in undesired_values: break
> >
> > But I'm not sure how common this idiom actually is.
> 
> Extremely common, and not only in Python.
> 
It's the classic C 'for' loop.

'for' in C is essentially a while with an initialiser for the loop
variable.

-- 
Chris Green
·



More information about the Python-list mailing list