Hi Here is my question: I need to use a combination of conditions in order to execute the function i want. I want something like this: if (value1 <= x && value1 >= y) OR (value1 <= z && value1 >= n); doTheFunction; } else { dontDoTheFunction } What is the right way to do this? Thanks in advance
I'd write it slightly different: if ((value1 <= x) && (value1 >= y)) || ((value1 <= z) && (value1 >= n)); doTheFunction; } else { dontDoTheFunction } Code (markup): The extra parens are because I can never remember the rules of presidence and I use the "||" operator by habit because I use several different languages.
Finally it works this way if ((value1 <= x && value1 >= y) || (value1 <= z && value1 >= n)){ doTheFunction; } else { dontDoTheFunction; } PHP: The script need parenthesis but only two sets in oder to group the two conditions. And i had also forget to put the "{" symbol at the end of the first line. I use ";" instead and this was wrong. Thank you for your help
If you learn the operator precedence, you will be able to optimize your expressions. http://php.net/manual/en/language.operators.precedence.php
actually your in the right way. occasionally when i do "or" statement specially 2 or more conditions i do it like this <code> if condition1 { do method; return; } if condition2 { do method; return; .... </code> if the first conditions is satisfied automatically execute the method the cut the process in that way i can instantly eliminating the process of reading the following conditions.