If statements and conditions

Started by
3 comments, last by Fruny 19 years, 3 months ago
hey, is there a way to give an if statement more than one condition. ex. if mystring == open door and myveriable == 2.
Advertisement
Connect the two with a boolean AND operator, usually a && in most languages:
if ((n == 5) && (m == 8)) {...}

&& evaluates to true if both the conditions it connects evaluate to true.

okay,

thanks.
dunno if this is good programming practice or not,
but heres another way:
int someint  = 2;int someint2 = 4;if(someint==2){   if(someint2==4)   {     // code will happpen if both conditions are true;     // same as if(someint==2 && someint2==4)   }}


Fruny - fixed typo (= vs ==) and formatting.
I pity the fool that uses numerical operators as boolean evaluators!
Quote:Original post by supercrazy7474
dunno if this is good programming practice or not, but heres another way:


Depends on the context. Sometimes it may be a good idea, some time it may not be.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement