On Oct 13, 11:27�am, Ethan Furman <et...@stoneleaf.us> wrote: > Mensanator wrote: > > On Oct 13, 3:44 am, John Reid <j.r...@mail.cryst.bbk.ac.uk> wrote: > > >>while not done: > > >>seems very dangerous to me as you'd have to > > >>del done > > >>before writing the same construct again. That's the sort of thing that > >>leads to errors. > > >Duh. I won't write silly code like that either. > >If I need more than one loop structure then I'll > >do something like > > > while not done_with_this > > > while not done_with_that > > >Besides, since I _always_ initialize the flag > >before entering a loop, the flag can be reused > >and doesn't have to be deleted (as long as the > >loops aren't nested). And since I don't use goto, > >there's no chance the initialization can be avoided. > > >>Initialising the flag is just another line of code that has to be > >>interpreted later. I didn't notice the initialisation in your original post. > > > "Just another line that has to be interpreted later" > > is a strange comment in the context of "del done". > > I don't believe John is advocating using it, just pointing out that an > extra line is needed -- whether the extra line is "del loop_control_var" > or "loop_control_var = False", it's still an extra line. > > Mind you, I'm not saying you should change the way you program as it > seems to work for you, just that there are other ways to write good > clean programs.
And I'm not saying John nor the OP should stop using what works for them. But there are certainly valid reasons for "don't use while True" to be on the "Best Practices" list. After all, how many times hve you put 'break' in a loop comprehension? > > ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list