Equality ( = )

What is it?

The Equality operator is used to compare two values for similarity. If the values are identical, the expression returns a value of True; otherwise, the value will be False.

What is the Syntax?

The equality symbol is =. In expressions, equality operations are written as follows.

Operand1 = Operand2

Why might I want to use this?

If you develop an application that asks an end user trivia questions, an equality operator would be used to test whether the answer given by the user is equal to the correct answer to the current question. Such a comparison would be implemented in a similar manner to the following example:

if:( AnswerGiven = CorrectAnswer )
{
"Correct!"
}
else
{
"Try again!"
}

In the above example, if the aim of the question is to guess a number between 1 and 10, and the value of CorrectAnswer is 4, the user will see the message “Try again!” in all circumstances until he submits an answer of 4, at which point the message “Correct!” is displayed.

 

<< Previous: True and False: Binary Terms | Next: Not Equal ( < > ) >>