Writing if (x = 5) assigns 5 to x instead of comparing. I'll show you why this compiles but does the wrong thing. The condition is always true because assignment returns the assigned value.
You prevent this by writing constants first: if (5 == x) causes a compiler error if you type = instead of ==. You can't assign to a literal, so the mistake becomes visible. Another mistake is if (x == 5); with a semicolon.
The empty statement runs when x is 5, then the next block always runs. Your if does nothing because the semicolon ends it.