Boolean expressions are those that always evaluate to either true
or false
. Here are some examples of operators that usually can be found within a boolean expression:
- relational and equality operators
- logical negation,
!
- type operators
Relational expressions
A relational expression consists of two or more expressions whose values are compared to determine whether the relationship stated by the relational operator is satisfied (Schmalzl, 1999).
Example of relational and equality operators:
Expression | Description |
---|---|
x < y | Less than |
x > y | Greater than |
x <= y | Less than or equal |
x >= y | Greater than or equal |
x == y | Equal |
x != y | Not equal |
Console.WriteLine($"1 > 2 is {1 > 2}");
Console.WriteLine($"1 < 2 is {1 < 2}");
Console.WriteLine($"1 <= 1 is {1 <= 1}");
Console.WriteLine($"2 >= 2 is {2 >= 2}");
Console.WriteLine($"2 == 2 is {2 == 2}");
Console.WriteLine($"2 != 2 is {2 != 2}");
The output:
1 > 2 is False
1 < 2 is True
1 <= 1 is True
2 >= 2 is True
2 == 2 is True
2 != 2 is False
Live-code example
References
- Schmalzl, J. (1999, July 5). Relational Expressions. Retrieved from http://earth.uni-muenster.de/ joergs/doc/f90/lrm/lrm0064.htm