Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Mar 9, 2010 12:48:17 GMT -8
when doing an if statment. and you want one thing and another thing to work, OR, something else, and something else to work. how would you write that?
Example if ( (This && this work) || (This && this Work) )
would you write it like so?
if ((location.href.match(/wormocodes/i) && pb_username=="wormo") || (location.href.match(/thisnthat/i) && pb_username=="topeka")) {
having the 'ifs ands' in parentheses make them work first, then the 'OR' part? like a math problem (9-8)*(1+1) , or would those extra set of () invalidate the if statement?
|
|
|
Post by Wormopolis on Mar 9, 2010 19:06:59 GMT -8
c++ follows the hierachy that algegra does basically.
parenthesis have higher priority then AND then OR
so in your example, you could go without the added internal ( ).. and the ANDs would parse first, get results, then OR the results.
using ( ) is good practice however, because if you want to group a bunch of OR stuff.. and ADN it to something else:
(A || B || C || D) && E
would not be the same as
A || B || C || D && E
because it would AND D with E, THEN OR the result with A B C
there are many tricks too boolean algebra. if youget a chance, pick up a book about them. you can convert lines like
!(A || B)
into
!A && !B
where ! means NOT
and something like A && B || A && C
can become A && (B || C)
|
|
Topeka
Junior Member
Posts: 94
Topeka said 0 great things
|
Post by Topeka on Mar 9, 2010 20:40:15 GMT -8
ok i can see this. Its sorta like simple algrebra from last year. where you had to negate a statement like (blue and not white or green) answered (not blue or white and not green). i probably will use ( ) for awhile, i got into a habbit of typing ( ) in my calculator when not needed, and it seems to be the same here. Thanks for the lesson wormo. Heres an apple for the teacher. haha lol. Thanks alot. im understanding this one step at a time.
|
|
|
Post by Wormopolis on Mar 9, 2010 23:48:01 GMT -8
glad to help!
|
|