Equality Operator (==)
Whenever you see two equal sign in arrow (
==), this is the equality operator. Do not confuse the equality operator with the assignment operator which is only one equal sign (
=). What the equality operator does is it compares the two values on each side of itself and determines if they are equal or not. If they are equal, then this condition is
true. The program will then execute the code in between the two curly braces (
If these two values aren't equal, then this condition is
false. The code in between the two curly braces is skipped over and the program continues to run.
Here is an example of the equality operator in use:
In this example, if the variable
inning equals the number
10, then the message
Game Over gets displayed in an alert box. If the variable
inning does not equal
10, then the code in between the curly braces is skipped over and the program would continue to run.