Why is IF statement executing on itself
You have a rogue semi-colon.

Splitting your code up on the end of statements you get:

1. x = 5; 
2. Serial.println (x);
3. if (x == 0);
4. { // stuff }


With the semi-colon after the if it terminates the if before the opening block {, and that block becomes a completely separate statement detached from the if.