Loop until condition is true

Magnus Lycka lycka at carmen.se
Tue Jun 21 06:05:25 EDT 2005


Remi Villatel wrote:
> 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.

This is a common Python idiom. I think you will get used to it.


> Is there a better recipe?

final_condition = False
while not final_condition:
     some(code)



More information about the Python-list mailing list