Evaluation of complex conditions

Richard Gaskin ambassador at fourthworld.com
Wed Oct 5 16:46:53 EDT 2011


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




More information about the use-livecode mailing list