Python: Code is ignoring the if and else
John Ladasky
john_ladasky at sbcglobal.net
Fri Aug 2 21:39:43 EDT 2013
On Friday, August 2, 2013 5:40:52 PM UTC-7, kevin... at gmail.com wrote:
> Basically, my code is ignoring the if's and else's. I don't get why.
> Everything appears to be positioned correctly, but for some odd reason, even
> after an if, the program also runs the else as well.
Look carefully at your indentation. One "else" statement is at the same indentation as a "for" statement rather than an "if" statement. So what, you say?
http://docs.python.org/2/tutorial/controlflow.html
"Loop statements may have an else clause; it is executed when the loop terminates through exhaustion of the list (with for) or when the condition becomes false (with while), but not when the loop is terminated by a break statement."
I don't know of any other computer programming language besides Python which has the "for...break...else" idiom. However, I know quite a few that do not. I find it useful in many situations.
More information about the Python-list
mailing list