I want to write an if statement that if any one single condition becomes true at a given moment, the function will run. How would i format the conditions(4) into an if statement, could i just seperate them by commas like this ?
if(X > 100, X < 100, Y > 100, Y < 100)
{
//do this if any single condition is true
}
It's also wise to remember that even the OR operator has it's own rank within the order of precedence. So, rather than relying on memory to work out which functions have the greatest precedence, I'd always wrap each condition in brackets.
Robin2:
Be aware that if you have (say) 3 tests in one IF statement
eg if ( A > 6 || B < 7 || C > 23) {
there are 2**3 = 8 possible outcomes (or are there more?). It is very easy to make a mistake and test for the wrong outcome.
No. There are only two possible outcomes, either the statement is true or it is false.
There is one way to reach a false outcome, when all the tests are false.
There are three ways to reach a true outcome, when any one of the tests is true.
If more than one test is true, it won't change the outcome. They are not exclusive ORs.
There are 8 possible results of the 3 tests.
joelaflop:
I want to write an if statement that if any one single condition becomes true at a given moment, the function will run. How would i format the conditions(4) into an if statement, could i just seperate them by commas like this ?
if(X > 100, X < 100, Y > 100, Y < 100)
{
//do this if any single condition is true
}
or what is the proper way to format this?
Those commas won't compile much less work.
You need to spend time learning Boolean Operators and Compound Operators, for a start:
Booleans are on the left side about halfway down, Compounds are left bottom.
(( X < 100 ) || ( X > 100 )) is the same as ( X != 100 ), != is the opposite of ==, ! means NOT.
I want to write an if statement that if any one single condition becomes true at a given moment, the function will run. How would i format the conditions(4) into an if statement,...
Ohhh ... wish you wouldn't have asked that!
Four mutually exclusive conditions in one if statement: