Operators that compare two values and return a true or false (or boolean) value based on their relation to one another. They are also sometimes called comparison operators. For instance, "10 > 5" means the number 10 is greater than 5, assuming we use the decimal number system (my personal favorite). It would return a true value because it is true. Different programming languages and notations use different symbols, but here are some common ones.

= or == means "is equal to"
> means "is greater than"
< means "is less than"
>= means "is greater than or equal to"
<= means "is less than or equal to"
<> or != means "is not equal to"

These are the notations that I know. /msg me or write up ones from other systems if you like.

You should also check the documentation for the language you are using, because some relational operators do not return a truly boolean value but an integer. For instance, one of Java's primitive data types is boolean, but in C, relational operators return an integer. Some languages have these operators return 0 and 1, others 0 and -1. Understanding the return value of relational operators is very, very important.

Note that in some languages, the ordering of the symbols in the digraphs is important, while in others it is not. For instance, in the BASIC shipped with the TRS-80 (Models I - IV), it is legal to express "greater than or equal to" as either ">=" or "=>" but that in C (for instance) the only allowable sequence is ">=".

Also note that the operator for "is equal to" varies from language to language. In BASIC, the symbol "=" may be the relational operator if used in a conditional context (the condition of an IF statement, for instance) or the assignment operator (in a LET statement, for example). Pascal avoids this by defining the symbol ":=" to be the assignment operator and "=" to be the relational operator, while C defines "==" to be the relational operator and "=" to be the assignment operator.

Perl adds somewhat to the confusion, since it defines relational operators for strings as well, and although they are semantically identical to the mathematical relational operators, they're written differently: "lt", "gt", "le", "ge", "eq", "ne", "cmp" for "less than", "greater than", "less than or equal to", "greater than or equal to", "is equal to", "is not equal to", and "compare", respectively.

Log in or registerto write something here or to contact authors.