control structures (was "Re: Sins")

Gordon McMillan gmcm at hypernet.com
Sat Jan 8 12:36:47 EST 2000


John Skaller wrote:
[snip]
>  Current looping constructions are so bad,
> that the simplest of uses cannot be expressed
> using them : searching a list for an element
> cannot be written correctly:
> 
>  for i in X: 
>   if X[i]=e: goto Found
>  print "Not Found"
>  goto next
>  Found: ...
>  next
> 
> YUKKKKKK!!! There is no natural way to do this.
> We fall through the loop on failure, instead
> of success. (using a flag, or testing anything
> afterwards, is not acceptable as a solution).

That's the reason that Python has the "for 
.. else" construct that William Tanksley 
hates so much.

 for i in X: 
   if X[i]==e: 
     # do the "found" thing
     break
 else:
   print "Not Found"
 
responses-redirected-to-Tanksley-ly y'rs


- Gordon




More information about the Python-list mailing list