The rap against "while True:" loops

Steven D'Aprano steve at
Sun Oct 11 10:01:51 CEST 2009

On Sat, 10 Oct 2009 20:15:21 +0000, kj wrote:

> I use "while True"-loops often, and intend to continue doing this "while
> True", but I'm curious to know: how widespread is the injunction against
> such loops?  Has it reached the status of "best practice"?

Such an injunction probably made more sense back in the days of single-
tasking computers. Back in ancient days when dinosaurs walked the Earth, 
and I was programming in THINK Pascal on Apple Macintosh System 6, I'd go 
into nervous palpitations writing the equivalent of "while True" because 
if I got it wrong, I'd lock up the machine and need to hit the power 
button. (At least if I was still testing in the THINK Pascal IDE, and had 
the whole range of debugging options turned on, I could interrupt it.)

These days, I must admit I still have a tiny little shiver whenever I 
write "while True", but that's entirely irrational and I pay no attention 
to it.


More information about the Python-list mailing list