Old 11-07-2008, 02:21 AM   #1
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default Q: Branching syntax ?

Is this syntax valid?
Code:
FORWARD = 1;
BACK = 2;
UP = 3;

type == (FORWARD || BACK || UP) ? (
   ...;
);
or does it have to be:
Code:
(type == FORWARD || type == BACK || type == UP) ? (
   ...;
);
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is online now   Reply With Quote
Old 11-07-2008, 12:52 PM   #2
LOSER
Human being with feelings
 
Join Date: May 2006
Posts: 2,373
Default

Both are valid, but both yield different results.

type == (a || b || c) will be true when either either a,b or c are NOT 0 AND type is 1 .... or when either a,b and c are 0 AND type is 0 as well.

(type == a || type == b || type == c) will be true when either type is a OR type is b OR type is c.
LOSER is offline   Reply With Quote
Old 11-07-2008, 04:11 PM   #3
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

OK, thank you

I understand now.
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is online now   Reply With Quote
Old 11-07-2008, 06:47 PM   #4
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default

Quote:
Originally Posted by LOSER View Post
Both are valid, but both yield different results.

type == (a || b || c) will be true when either either a,b or c are NOT 0 AND type is 1 .... or when either a,b and c are 0 AND type is 0 as well.

(type == a || type == b || type == c) will be true when either type is a OR type is b OR type is c.
Yes basically Good Explanation.
liteon is offline   Reply With Quote
Old 01-22-2009, 04:38 AM   #5
Jeffos
Mortal
 
Jeffos's Avatar
 
Join Date: Dec 2008
Location: France
Posts: 1,969
Default

Quote:
Originally Posted by LOSER View Post
Both are valid, but both yield different results.

type == (a || b || c) will be true when either either a,b or c are NOT 0 AND type is 1 .... or when either a,b and c are 0 AND type is 0 as well.

(type == a || type == b || type == c) will be true when either type is a OR type is b OR type is c.
Hi!

About conditions: do you know if they're "optimized" ?
i.e. in (a || b), is b evaluated when a is true ?
i.e. in (a && b), is b evaluated when a is false ?
Jeffos is offline   Reply With Quote
Old 02-04-2009, 06:06 PM   #6
dub3000
Human being with feelings
 
dub3000's Avatar
 
Join Date: Mar 2008
Location: Sydney, Australia
Posts: 3,955
Default

Quote:
Originally Posted by Jeffos View Post
Hi!

About conditions: do you know if they're "optimized" ?
i.e. in (a || b), is b evaluated when a is true ?
i.e. in (a && b), is b evaluated when a is false ?
pretty sure it uses short-circuited evaluation. i.e. they're probably optimized.
dub3000 is offline   Reply With Quote
Old 02-05-2009, 10:05 AM   #7
LOSER
Human being with feelings
 
Join Date: May 2006
Posts: 2,373
Default

Quote:
Originally Posted by dub3000 View Post
pretty sure it uses short-circuited evaluation. i.e. they're probably optimized.
Yes, they are.

BTW (without wanting to sound cocky) you can simply test it:
Code:
desc:test
slider1:0<0,1,1>foo
@sample
slider1 = 0;
1 || slider1 = 10;
// 0 || slider1 = 10;
// 1 && ... etc
.. and then you can be 100% positive .
LOSER is offline   Reply With Quote
Old 02-05-2009, 01:56 PM   #8
Jeffos
Mortal
 
Jeffos's Avatar
 
Join Date: Dec 2008
Location: France
Posts: 1,969
Default

BTW (without wanting to sound cocky) it's more simply said in the doc, in Justin's laguage:
"y || z Returns logical OR of values. If y is nonzero, 'z' is not evaluated.
y && z Returns logical AND of values. If y is zero, 'z' is not evaluated."


... just for the joke!
but true: I've first supposed I didn't get any answer because of that but in fact, I think that people are so used to ||, &&, ... that they don't focus on this part of the doc
Jeffos is offline   Reply With Quote
Old 02-05-2009, 03:37 PM   #9
zildjohn01
Human being with feelings
 
Join Date: Dec 2008
Posts: 189
Default

When in doubt use parentheses.

Hope this doesn't sound too cockos
zildjohn01 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:25 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.