|
|
|
11-07-2008, 02:21 AM
|
#1
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
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 ...
|
|
|
11-07-2008, 12:52 PM
|
#2
|
Human being with feelings
Join Date: May 2006
Posts: 2,373
|
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.
|
|
|
11-07-2008, 04:11 PM
|
#3
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
OK, thank you
I understand now.
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
11-07-2008, 06:47 PM
|
#4
|
Human being with feelings
Join Date: Apr 2008
Posts: 510
|
Quote:
Originally Posted by LOSER
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.
|
|
|
01-22-2009, 04:38 AM
|
#5
|
Mortal
Join Date: Dec 2008
Location: France
Posts: 1,969
|
Quote:
Originally Posted by LOSER
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 ?
|
|
|
02-04-2009, 06:06 PM
|
#6
|
Human being with feelings
Join Date: Mar 2008
Location: Sydney, Australia
Posts: 3,955
|
Quote:
Originally Posted by Jeffos
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.
|
|
|
02-05-2009, 10:05 AM
|
#7
|
Human being with feelings
Join Date: May 2006
Posts: 2,373
|
Quote:
Originally Posted by dub3000
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 .
|
|
|
02-05-2009, 01:56 PM
|
#8
|
Mortal
Join Date: Dec 2008
Location: France
Posts: 1,969
|
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
|
|
|
02-05-2009, 03:37 PM
|
#9
|
Human being with feelings
Join Date: Dec 2008
Posts: 189
|
When in doubt use parentheses.
Hope this doesn't sound too cockos
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 02:25 PM.
|