Python IF THEN chain equivalence
jzakiya at mail.com
Thu Nov 13 23:31:45 CET 2008
On Nov 13, 5:21 pm, Alan Baljeu <alanbal... at yahoo.com> wrote:
> I think you should rethink your post. The first case you posted makes no sense in any language I know. Also, a whole lot of nested IF's is a bad idea in any language. In Python, you will end up with code indented 40+ characters if you keep going.
> ----- Original Message ----
> From: jzakiya <jzak... at mail.com>
> To: python-l... at python.org
> Sent: Thursday, November 13, 2008 5:06:53 PM
> Subject: Python IF THEN chain equivalence
> I'm translating a program in Python that has this IF Then chain
> IF x1 < limit: --- do a ---
> IF x2 < limit: --- do b ---
> IF x3 < limit: --- do c ---
> IF x10 < limt: --- do j ---
> In other words, as long as 'xi' is less than 'limit' keep going
> down the chain, and when 'xi' isn't less than 'limit' jump to end of
> chain a continue.
> Is this the equivalence in Python?
> IF x1 < limit:
> --- do a ---
> elif x2 < limit:
> --- do b ---
> elif x10 < limit:
> --- do j ---
> Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know athttp://ca.answers.yahoo.com
In the code the 'xi's and 'limit' are variables and the --- do letters
phrases are simply writes to any array: an_array[xi]=0
Actually, the code makes perfectly good sense, and is a necessity of
the algorithm I'm implementing, and works perfectly good in Forth, and
written quite nicely within a normal page width.
I was just hoping I could perform the equivalent chain in Python
having to grossly indent the source code past the normal width of a
But if that's the only way to do it in Python, then so be it.
More information about the Python-list