Evaluation of complex conditions

Pete pete at mollysrevenge.com
Wed Oct 5 20:26:01 EDT 2011


I just read the section in the manual about operator precedence and I think
perhaps I'm even more confused than I was!  It details a strict order of
precedence which seems to contradict the knowledge that condition evaluation
proceeds from left to right and stops as soon as a false one is found.

Maybe I'll try a few test cases.


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




On Wed, Oct 5, 2011 at 4:36 PM, stephen barncard <
stephenREVOLUTION2 at barncard.com> wrote:

> yeah , I don't know, sometimes stuff doesn't work exactly right so I try
> something else like
>
> if a is true
> then
>
> switch
>  case b = true
>  case c = true
>     do whatever
>  break
> end  switch
>
> end if
>
> or try reversing and/or
>
> if a is true then
>
> if (b is true and c is true) then
>   do whatever
> end if
>
> end if
>
> I know the above doesn't look right but this has come up many times and
> works for me.
>
> On 5 October 2011 16:25, Pete <pete at mollysrevenge.com> wrote:
>
> > 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
> > >
> > >
> > _______________________________________________
> > 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
> >
>
>
>
> --
>
>
>
> Stephen Barncard
> San Francisco Ca. USA
>
> more about sqb  <http://www.google.com/profiles/sbarncar>
> _______________________________________________
> 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