Programming Fundamentals/Relational Operators
Overview
editA relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality (e.g., 5 = 5) and inequalities (e.g., 4 ≥ 3).[1]
Discussion
editRelational operators give a Boolean value (data type that has one of two possible values to represent the two truths of logic) by evaluating the relationship between two operands.
Operator symbols and/or names can vary with different programming languages. Most programming languages use relational operators similar to the following:
Operator | Meaning |
<
|
less than |
>
|
greater than |
<=
|
less than or equal to |
>=
|
greater than or equal to |
==
|
equality (equal to) |
!= or <>
|
inequality (not equal to) |
Examples:
- 9 < 25
- 9 < 3
- 9 > 14
- 9 <= 17
- 9 >= 25
- 9 == 13
- 9 != 13
- 9 !< 25
- 9 <> 25
Note: Be careful. In math you are familiar with using the symbol = to mean equal and ≠ to mean not equal, but in many programming languages the ≠ is not used and the = symbol means assignment.
Key Terms
edit- relational operator
- An operator that gives a Boolean value by evaluating the relationship between two operands.