Evaluation of complex conditions

Pete pete at mollysrevenge.com
Wed Oct 5 19:25:59 EDT 2011


No, I mean:

If a is true then
   if (b is true or c is true) then
      do whatever
   end if
end if

I'm pretty sure if a was false, the second condition wouldn't be evaluated.

But you raise an interesting point - in your example, does the condition
inside the parens truly get evaluated first?

Pete
Molly's Revenge <http://www.mollysrevenge.com>




On Wed, Oct 5, 2011 at 3:59 PM, Bob Sneidar <bobs at twft.com> wrote:

> Yes, if by nested you mean:
> a is true and (b is true or c is true)
>
> The statement in parenthesis gets evaluated first.
>
> Bob
>
>
> On Oct 5, 2011, at 2:20 PM, Pete wrote:
>
> > Thanks, that's good to know.  I'm looking at using a pretty complex
> > condition with some of the conditions being trivial but others taking up
> > significant database access so sounds like I should leave the db access
> > conditions until last.
> >
> > Hmmm, now I wonder if nested if statements make any difference to this.
> > Probably not.
> >
> >
> > Pete
> > Molly's Revenge <http://www.mollysrevenge.com>
> >
> >
> >
> >
> > On Wed, Oct 5, 2011 at 1:46 PM, Richard Gaskin
> > <ambassador at fourthworld.com>wrote:
> >
> >> Pete wrote:
> >>
> >> I'm wondering how LC evaluates If statements with multiple conditions.
> >>> Are
> >>> all conditions evaluated before the overall result is checked for true
> or
> >>> false, or does evaluation proceed left to right and stop as soon as a
> >>> condition is found to be false?  Whichever method is used, is it
> affected
> >>> by
> >>> some conditions being enclosed in parens?
> >>>
> >>
> >> IIRC from discussions with Dr. Raney many years ago, at some point he
> >> implemented an optimization in which the first part of any
> multi-condition
> >> expression that satisfies the expression avoids the need for evaluation
> of
> >> other conditions.  This normally follows in left-to-right order, but of
> >> course using parens can alter the evaluation order.
> >>
> >> So in this conditional expression:
> >>
> >> if the short name of this cd is "Pete" and $user <> "pete" then
> >>
> >> If the short name of the card <> "Pete" then the engine wouldn't bother
> >> evaluating $user.
> >>
> >> --
> >> Richard Gaskin
> >> Fourth World
> >> LiveCode training and consulting: http://www.fourthworld.com
> >> Webzine for LiveCode developers: http://www.LiveCodeJournal.com
> >> LiveCode Journal blog: http://LiveCodejournal.com/**blog.irv<
> http://LiveCodejournal.com/blog.irv>
> >>
> >> ______________________________**_________________
> >> use-livecode mailing list
> >> use-livecode at lists.runrev.com
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >> http://lists.runrev.com/**mailman/listinfo/use-livecode<
> http://lists.runrev.com/mailman/listinfo/use-livecode>
> >>
> >>
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>



More information about the use-livecode mailing list