No the code
x != 5 will not work in the context you are asking. That is because != is a test of inequality, not one of assignment. What typically you do is list all the values you want to check against and then compare X to this list. If it is found, switch it to a value you know is not in the list, or assign it a new value and again check it against the list of excluded values.
How you do this can be numerous. You could use an array of "bad values" and loop through it. You could use a string of values and do a sub string search, you simply test it against each value in a nested if or even in a switch case if you wanted to (where you would setup the "default" case to be the ideal situation where it matched no cases).
It is up to you on which solution you want based on your problem domain. But it is all about the design.
I hope that answered your question.

"At DIC we be value testing code ninjas, so how much do you value your life?"