If statements and conditions
hey,
is there a way to give an if statement more than one condition.
ex.
if mystring == open door and myveriable == 2.
Connect the two with a boolean AND operator, usually a && in most languages:
&& evaluates to true if both the conditions it connects evaluate to true.
if ((n == 5) && (m == 8)) {...}
&& evaluates to true if both the conditions it connects evaluate to true.
dunno if this is good programming practice or not,
but heres another way:
Fruny - fixed typo (= vs ==) and formatting.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement