Confused about while statement

Roy Smith roy at panix.com
Thu May 20 21:45:42 EDT 2004


In article <40AD5DF2.69F2015A at alcyone.com>,
 Erik Max Francis <max at alcyone.com> wrote:

> EAS wrote:
> 
> > In theory, the following code should ask for the user to enter a value
> > for h
> > until he/she enters hello or goodbye.
> > 
> > h = "hi"
> > while h != "hello" or "goodbye":
> >         h = raw_input("Value for h:")
> > 
> > But the program keeps asking for a value no matter what I enter. Why
> > doesn't
> > it work?
> 
> You meant
> 
> 	while h != "hello" and h != "goodbye": ...

Or, perhaps even better,

   while h not in ("hello", "goodbye"):

The meaning is the same, but I think idiomatically, it's a closer match 
to the way you would say it in natural language.



More information about the Python-list mailing list