Complex if statement does not include 'NOT' Operator

Feb 7, 2015 at 10:31pm
Hello all.

I'm not sure if I was some weird syntax problem or the way Ive ordered things. But a conditional statement I have created is not performing the way I want it to.

1
2
3
4
5
6
...
else if ( !( xDif == -1 && yDif == 1 && prevXDif == 1 && prevYDif == 0 ) )
        {
            foundArr[lastX][lastY] = 1;
        }
...


When debugging, the condition was activated with the values:
1
2
3
4
xDif = -1
yDif = 1
prevXDif = -1
prevYDif = 0


However, I want the condition not to follow through as I am using the 'NOT' or '!' operator to negative the entire statement. For some reason, the line of code within the else if is still running.
Last edited on Feb 7, 2015 at 10:32pm
Feb 7, 2015 at 11:01pm
That's because in your else if statement you put

prevXDif == 1

while you passed the value of

prevXDif = -1

So that statement is evaluated to false, which causes all the "&&" and statements to be false. Since you have the "!" not value, your else if evaluates to true and runs the code.
Feb 7, 2015 at 11:16pm
I did to, I guess I needed someone else to point that out. I checked it like 5 times :P.

Many Thanks
Topic archived. No new replies allowed.