else clauses in while and for loops

Jeff Massung jmassung at magpiesystems.com
Mon Apr 17 20:26:49 EDT 2000

Donn Cave wrote in message <8dg14u$f08$1 at nntp6.u.washington.edu>...
>Yes, but if you look at the examples, they also use "break".  After a
>loop, "else" basically means "if no iteration of the loop met the
>conditions to break out."  It's a common usage, where in C we'd compare
>the final loop index with the maximum (or whatever) loop index to see
>if the loop ran all the way through.

I don't think that I'm following you, give me an example where the loop
ends, but the else wouldn't be executed and I think I'll better understand.

>| That could definitely be useful, because it would eliminate an "if"
>| statement right before the "while" statement. <SNIP> useful for debugging
>| purposes.

>I think I would go along with that if you took out "Extremely" - and then

Consider it gone ;)

>your paragraph would justify better on the right margin, too!  Seriously,
>"else" does invariably execute if the loop was never run once, but as
>mentioned above it also executes in other circumstances.

I think it would be better suited if it didn't execute under "other
circumstances". It would be nice to know _exactly_ when it would execute,
and only under 1 or 2 conditions (maybe that is the way it is now, I just
don't see it).


More information about the Python-list mailing list