Loop until condition is true
Tim Williams
tdw at tdw.net
Sat Jun 18 10:09:23 EDT 2005
----- Original Message -----
From: "Remi Villatel" <maxilys at SPAMCOP_tele2.fr>
> There is always a "nice" way to do things in Python but this time I can't
> find one.
> So far, all I got is:
>
> while True:
> some(code)
> if final_condition is True:
> break
> #
> #
>
> What I don't find so "nice" is to have to build an infinite loop only to
> break it.
If your final_condition is already defined outside the "while" then how
about
while not final_condition:
some(code)
Simplistically, this equates to
>>> x = 0
>>> while not x == 5:
... x += 1
...
>>> print x
5
:)
More information about the Python-list
mailing list