Language Elements and Reference:xpplrm

Comparison operators Foundation

All comparison operators are binary operators which compare the values of their operands with each other. When a comparison results in a match, these operators always provide the logical value .T. (true) as a result. They provide the value .F. (false) if the comparison does not result in a match. The following table shows all comparison operators available in Xbase++.

Comparison operators
Operator Data type Operation
== C, D, L, M, N, U test for exact equality
A, B, O test for identical references
= C, D, L, M, N, U test for equality *)
A, B, O test for identical references
<> # != C, D, L, M, N, U test for inequality *)
> C, D, L, M, N greater than *)
>= C, D, L, M, N greater or equal *)
< C, D, L, M, N less than *)
<= C, D, L, M, N less or equal *)
$ .IN. C, M, A, N test for value in set, string is within string
  1. Character string comparisons are dependent on SET EXACT, SET COLLATION and SET LEXICAL.

There are two different equality operators: the simple equality operator = and the exactly equal operator ==.

The simple equality operator cannot test all data types for equality. Also, comparison of character strings using this operator depends on the settingsSET EXACT ON|OFF, SET COLLATION and SET LEXICAL ON|OFF. SET EXACT specifies whether blank spaces at the end of the character strings are considered. SET LEXICAL determines whether character strings are compared according to lexical rules or by their ASCII values (see the chapter "Operations with Character Values").

The exactly equal operator can compare values of any data type. Variables of data types array (A), code block (B) and object (O) are tested to see whether they reference identical values. In comparing character strings, the exactly equal operator returns the value .T. (true) when all characters of both character strings are identical - binary comparison. When two variables of A, B or O data type are compared, the comparison results in true only when both variables reference the same array, code block or object.

Normally both operands in a comparison must have the same data type. However, the equality operators can compare all data types with NIL. A comparison with NIL returns the value .T. (true) only when the value of both operands is equal to NIL.

With the exception of the operators ==, $ and .IN., all comparison operators depend on SET EXACT, SET COLLATION and SET LEXICALwhen comparing character strings with one another. The $ and .IN. operator tests whether a string (left operand) is contained in a another character string (right operand), if a value (left operand) is in an array (right operand) (see the sections on the individual data types in the chapters discussing "Operators and Operations").

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.