Evaluation of complex conditions

stephen barncard stephenREVOLUTION2 at barncard.com
Wed Oct 5 19:36:40 EDT 2011


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>



More information about the use-livecode mailing list