![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
How do I properly code up nested arguments for an "if" statement?
Example: two variables "varA" and "varB" have been assigned their values. I want to check what those values are before acting on the rest of the script: specifically, "varA" should be some value "foo" AND "varB" should be neither "bar" or "baz".
Here's how I thought it should go:
if (varA == "foo") && ( (varB != "bar") || (varB != "baz") )
{
do something;
}
When I do this, though, it seems to ignore the "varB" stuff and only acts on all instances where "varA" is "foo". The problem must be in how I nest the "varB" conditions, since if I remove one of them and fix the parenthesis accordingly, it works for that value of "varB". I have no idea how to make it work for my needs, however.
Thanks for y'alls input.
EDIT: Figured it out. Boolean fail on my end >|
no subject
Date: 2010-03-20 04:29 pm (UTC)if varA == "foo" && !(varB == "bar" || varB == "baz")
no subject
Date: 2010-03-21 04:45 am (UTC)But yeah, I'd forgotten the most basic of logic design elements, and things like that are only slightly more annoying than forgetting something like a semicolon -_-