control structures (was "Re: Sins")

Mark Jackson mjackson at wc.eso.mc.xerox.com
Sun Jan 9 21:10:10 EST 2000


"Gordon McMillan" <gmcm at hypernet.com> writes:

> > > Gordon McMillan wrote:

> > > >  for i in X:
> > > >    if X[i]==e:
> > > >      # do the "found" thing
> > > >      break
> > > >  else:
> > > >    print "Not Found"

> As one who regularly uses the searching algorithm above, I 
> find it highly useful. I find "if seq:" to be useful for testing for an 
> empty sequence. I'm not going to defend the spelling of the 
> construct, or it's description in the Language Ref, but it *is* 
> very useful.

The use of "else" as the keyword here is something I find jarring.  To
me, at least, it suggests the suite should be executed if the for loop
*doesn't* terminate normally (i.e. when there's a break) rather than
the opposite.  Same thing with while. . .else.

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
    Faced with the choice between changing one's mind and proving
    there is no need to do so, almost everybody gets busy on the proof.
				- John Kenneth Galbraith





More information about the Python-list mailing list