if and if

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
Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

if and if

Post by Samuele » Tue Mar 15, 2022 12:47 pm

Hi, how can i write a conditional

Code: Select all

If something and if somethingElse then DoSomething 
?
Thanks!
Samuele.

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: if and if

Post by Klaus » Tue Mar 15, 2022 12:53 pm

Just leave out one IF:

Code: Select all

...
if thisandthat AND thatandthis then
...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: if and if

Post by dunbarx » Tue Mar 15, 2022 1:39 pm

Samuele.

What Klaus said.

If you are just learning about this, experiment also with the "switch" structure, which oftentimes is easier to manage and read than complex "if/then" structures:

Code: Select all

switch
  case thisandthat
  case thatandthis
    doSomething
    break
  case whatever
    doSomethingElse
  break  
end switch
Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: if and if

Post by dunbarx » Tue Mar 15, 2022 2:44 pm

Going back to the "if" method, you have to understand how LiveCode works.

The statement that Klaus mentioned is really this:

Code: Select all

if (thisandthat AND thatandthis) then
You can see that there is only a single "if", as there must be, and that the more "complicated" portion in parentheses is evaluated independently. If that evaluation returns "true", then the "if" will fire.

Craig
Last edited by dunbarx on Tue Mar 15, 2022 5:50 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: if and if

Post by richmond62 » Tue Mar 15, 2022 4:34 pm

Not a bad idea to learn a bit of basic logic and the
satisfaction of truth conditions.

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: if and if

Post by Klaus » Tue Mar 15, 2022 4:46 pm

dunbarx wrote:
Tue Mar 15, 2022 2:44 pm
Going back to the "if" method, you have to understand how LiveCode works.

The statement that Klaus mentioned is really this:

Code: Select all

if (thisandthat AND thatandthis) then
You cans that there is only a single "if", as there must be, and that the more "complicated" portion in parentheses is evaluated independently. If that evaluation returns "true", then the "if" will fire.

Craig
Actually I really meant:

Code: Select all

if (thisandthat) AND (thatandthis) then
:-D

Samuele
Posts: 282
Joined: Mon Oct 11, 2021 7:05 pm
Location: Italy

Re: if and if

Post by Samuele » Tue Mar 15, 2022 5:07 pm

Thanks, the brackets are necessary?
Samuele.

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: if and if

Post by Klaus » Tue Mar 15, 2022 5:12 pm

No, but they make it easier to read for the developer and also LC!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: if and if

Post by dunbarx » Tue Mar 15, 2022 5:52 pm

Richmond.
Not a bad idea to learn a bit of basic logic and the
satisfaction of truth conditions.
Always, I suppose, but I will bet the issue here is LC syntax, not knowledge of how the world works.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: if and if

Post by richmond62 » Tue Mar 15, 2022 6:38 pm

Ha, ha, ha . . . all one has to do is look at Russia to see that basic logic has fuzz to do with how the world works.

But computers and computer programming are not the world.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”