Boolean expressions using relational operators

A Boolean expression is similar to a numeric expression or a string expression in that it yields a single value when evaluated. In the case of a Boolean expression, that value is either true or false. (Recall that a numeric expression produces a number when evaluated and a string expression a string).

Here are some examples of Boolean expressions:

Boolean expression This expression would be true if
strSex = "male" the value of the variable strSex were "male"; otherwise, it would be false
strSex.substring (0,1) = "m" the first letter of the variable strSex were "m"; otherwise, it would be false
strOne < strTwo the value of the variable strOne came before that of strTwo in alphabetical order; otherwise, it would be false
intOne < 100 the value of the variable intOne were less than 100; otherwise, it would be false
intAge1 = intAge2 the values of the variables intAge1 and intAge2 were the same; otherwise, it would be false

Note that some of these Boolean expressions involve numeric data and others string data. When comparing strings, alphabetic order is tested. For example, "Bob" is less than "Charlie" because it comes before it in alphabetic order and "Box" is greater than "Bob" because it comes after it.

Like numeric and string expressions, Boolean expressions can be as complex as you wish. The examples shown above use the relational operators equal (=) and less than (<). You can use other relational operators in your Boolean expressions:

Relational
Operator
Meaning
= equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
<> not equal to


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.