Python IF THEN chain equivalence
Mensanator
mensanator at aol.com
Thu Nov 13 20:18:12 EST 2008
On Nov 13, 4:39 pm, Grant Edwards <invalid at invalid> wrote:
> On 2008-11-13, jzakiya <jzak... at mail.com> wrote:
>
> > 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 ---
> > THEN
> > THEN
> > -----
> > THEN
> > THEN
> > THEN
>
> The placement of the THEN statements makes absolutely no sense
> in any language I've ever seen.
It looks like Visual Basic.
IF a THEN
do_a
IF b THEN
do_b
IF c THEN
do_c
END IF
END IF
END IF
Words different, but same structure.
>
> > 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 ---
>
> No. That's not the same at all.
>
> Here's one solution:
>
> while True:
> if x1 > limit: break
> do a
> if x2 > limit: break
> do b
> if x3 > limit: break
> do c
> ...
> if x10 > limit: break
> do j
> break
>
> --
> Grant Edwards grante Yow! Eisenhower!! Your
> at mimeograph machine upsets
> visi.com my stomach!!
More information about the Python-list
mailing list