dsh8290 at rit.edu
Tue Feb 6 20:15:16 CET 2001
On Tue, Feb 06, 2001 at 04:15:21PM +0000, Jay O'Connor wrote:
| Aahz Maruch wrote:
| > In article <mailman.981466899.30238.python-list at python.org>,
| > Simon Brunning <SBrunning at trisystems.co.uk> wrote:
| > > From: Langa Kentane [SMTP:LangaK at discoveryhealth.co.za]
| > >>
| > >> Why is is it while 1:
| > >> would while 2:
| > >> or while 3: work?
| > >
| > >Yup - any non-zero number is considered true. They wouldn't do anything
| > >different, though, and they just might confuse someone. (Why 2?)
| > Well, let's split the difference:
| > while 2.5:
Shouldn't that be 1.5 ? ;-)
| Umm..then how about a counter? Would this work?
| x = 100
| while x:
| print x
| x -= 1
| Yeah, just tried it...it works.
| Umm...anyone really like it? :)
for x in range( 100 , 0 , -1 ) :
With for you only have 1 one line that describes the entire loop,
instead of 3 lines that are spread about. You also have no chance of
forgetting to (de/in)crement the counter when you get to the end of
the loop body.
More information about the Python-list