Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51834

Re: Python: Code is ignoring the if and else

Newsgroups comp.lang.python
Date 2013-08-02 18:39 -0700
References <c6702eb3-494a-4359-84ef-d6679c09df35@googlegroups.com>
Message-ID <dfa6368b-565b-4512-8755-ef36fd2719cd@googlegroups.com> (permalink)
Subject Re: Python: Code is ignoring the if and else
From John Ladasky <john_ladasky@sbcglobal.net>

Show all headers | View raw


On Friday, August 2, 2013 5:40:52 PM UTC-7, kevin...@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-02 17:40 -0700
  Re: Python: Code is ignoring the if and else MRAB <python@mrabarnett.plus.com> - 2013-08-03 02:38 +0100
  Re: Python: Code is ignoring the if and else John Ladasky <john_ladasky@sbcglobal.net> - 2013-08-02 18:39 -0700
    Re: Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-02 18:44 -0700
      Re: Python: Code is ignoring the if and else Chris Angelico <rosuav@gmail.com> - 2013-08-03 02:56 +0100
      Re: Python: Code is ignoring the if and else Joshua Landau <joshua@landau.ws> - 2013-08-03 03:11 +0100
        Re: Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-02 19:24 -0700
          Re: Python: Code is ignoring the if and else Terry Reedy <tjreedy@udel.edu> - 2013-08-03 01:04 -0400
            Re: Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-03 13:12 -0700
  Re: Python: Code is ignoring the if and else Terry Reedy <tjreedy@udel.edu> - 2013-08-02 21:42 -0400
    Re: Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-02 18:46 -0700
  Re: Python: Code is ignoring the if and else Dave Angel <davea@davea.name> - 2013-08-03 03:34 +0000

csiph-web