if condition1 or condition2 or condition3 then...

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

if condition1 or condition2 or condition3 then...

Post by jalz » Sun Jun 15, 2014 8:48 pm

Hi Guys,

Is there a neat way of writing if with two or statements? I'm sure I can write nested ifs or a switch/case, but is there a more succinct way of writing this with an if statement?

Thanks
Jalz

Code: Select all

      put the long id of control x into tLong
      if (tLong contains "field" AND tLong contains "group") OR  
      (tLong contains "button" AND tLong contains "group") OR
      (tLong contains "graphic" AND tLong contains "group") 
      then
         //do something
      else
         // do something else
      end if
Thanks

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: if condition1 or condition2 or condition3 then...

Post by bn » Sun Jun 15, 2014 9:03 pm

Hi Jalz,

you could write:

Code: Select all

   put "field,button,graphic" into tObjects
   put the long id of control x into tLong
   
   if tLong contains "group" AND  word 1 of tLong is among the items of tObjects then
      //do something
   else
      // do something else
   end if
Kind regards
Bernd

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: if condition1 or condition2 or condition3 then...

Post by jalz » Sun Jun 15, 2014 9:17 pm

Hi Bernd

Thats a really elegant way of doing it! I can easily increase the tObjects keywords if I need to with the minimal of fuss

Many thanks
Jalz

Post Reply