Not Equal ( < > )

What is it?

The Not Equal operator behaves in the exact opposite way to the Equality operator discussed in the previous section. The operator takes two operands and, if these operands are equal, returns False. If they are not equal, the expression returns True.

What is the Syntax?

The Not Equal operator is represented by the following notation:

operand1 <> operand 2

Why might I want to use this?

The not equal operator can be used in almost all situations where an equality operator could be used instead, although clearly in this case the opposite result will be achieved.

If you have an application that asks its users to change their password on a regular basis, but you want to prevent them from re-using their last password, you could use the following expression to validate the new password.

if:( NewPassword <> OldPassword )
{
[Change the user's password]
"Your password was successfully changed."
}
else
{
"Your new password must be different to the old one."
}

If the user’s old password (OldPassword) was “gymkhana123” and the new password (NewPassword) they enter is “gymkhana124”, the operator compares the two strings and, as they are not identical, will change the password and return a string containing the message "Your password was successfully changed".

 

<< Previous: Equality ( = ) | Next: Less Than ( < ) and Greater Than ( > ) >>