Page 1 of 1

if and if

Posted: Tue Mar 15, 2022 12:47 pm
by Samuele
Hi, how can i write a conditional

Code: Select all

If something and if somethingElse then DoSomething 
?
Thanks!

Re: if and if

Posted: Tue Mar 15, 2022 12:53 pm
by Klaus
Just leave out one IF:

Code: Select all

...
if thisandthat AND thatandthis then
...

Re: if and if

Posted: Tue Mar 15, 2022 1:39 pm
by dunbarx
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

Re: if and if

Posted: Tue Mar 15, 2022 2:44 pm
by dunbarx
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

Re: if and if

Posted: Tue Mar 15, 2022 4:34 pm
by richmond62
Not a bad idea to learn a bit of basic logic and the
satisfaction of truth conditions.

Re: if and if

Posted: Tue Mar 15, 2022 4:46 pm
by Klaus
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

Re: if and if

Posted: Tue Mar 15, 2022 5:07 pm
by Samuele
Thanks, the brackets are necessary?

Re: if and if

Posted: Tue Mar 15, 2022 5:12 pm
by Klaus
No, but they make it easier to read for the developer and also LC!

Re: if and if

Posted: Tue Mar 15, 2022 5:52 pm
by dunbarx
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

Re: if and if

Posted: Tue Mar 15, 2022 6:38 pm
by richmond62
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.