On 2008-11-14 00:19, jzakiya wrote: > On Nov 13, 5:48 pm, "M.-A. Lemburg" <[EMAIL PROTECTED]> wrote: >>>> From: jzakiya <[EMAIL PROTECTED]> >>>> To: [EMAIL PROTECTED] >>>> 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 --- >>>> THEN >>>> THEN >>>> ----- >>>> THEN >>>> THEN >>>> THEN >> You should probably consider using a function and then >> convert the conditions to define return points: >> >> def do_something(...args...): >> >> if x1 >= limit: >> return >> ...do a... >> if x2 >= limit: >> return >> ...do b... >> etc. >> >> That is provided I understand the flow of control in your >> example... it's kind of strange to have THEN mark the *end* >> of the then-branch in an if-then-else construct. > > It's interesting to see people think it's strange to have code that > has multiple nested levels of IF THEN.
Not at all, that's fairly common in a lot of languages. It's not common to mark the end of the then-part using the THEN keyword, though. You'd normally expect the body of the then-part after the keyword. > Apparently you haven't seen > any Forth, assembly, et al code. All you're doing is having the branch > point for each conditional be the end of the chain, otherwise it falls > through to the code after the conditional. This is done all the time > in languages that let you actually manipulate the hardware. > > Just as a suggestion :-) a little humility would go a long way toward > being open minded and receptive to different paradigms. Without giving any hint as to what the quoted snippet of code is written in, how do you expect people to make any sense of it ? Especially when using an RPN stack oriented language in a Python forum. There's a reason why we hide Python byte code running on the VM stack machine from Python users ;-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 14 2008) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2008-11-12: Released mxODBC Connect 0.9.3 http://python.egenix.com/ :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 -- http://mail.python.org/mailman/listinfo/python-list