Data types and Operators

Operator <> != # Foundation

Not equal operators (binary): testing two values for inequality.

Syntax
<Expression1> <> <Expression2>
<Expression1> != <Expression2>
<Expression1> # <Expression2>
Parameters
<Expression>
<Expression1> and <Expression2> are expressions of the same data type or the value NIL. The values of the expressions are tested for inequality. Values of each data type can also be tested for not equal NIL.
Description

The not equal operator compares two values of the same data type and returns the result of the comparison as a logical value. The result is .T. (true) only when the value of <Expression1> is not equal to <Expression2>. Otherwise it is .F. (false).

Comparison with NIL

The not equal operator can compare values of all data types (including array, code block, and object) with the value NIL. In this case .F. (false) is returned only when both expressions are equal to NIL.

Comparison of characters

The settings of SET EXACT ON | OFF and SET LEXICAL ON | OFF are taken into account in comparing characters or character strings (see example). When SET LEXICAL is set to OFF, characters are compared with each other based on the collation table specified via the SET COLLATION command.

With SET EXACT OFF, the characters are compared up to the length of the right character string <Expression2>. With SET EXACT ON, the characters are compared up to the length of the left character string <Expression1> and trailing blanks are not considered. If <Expression2> contains a null string (""), the not equal operator always returns the value .F. (false) with SET EXACT OFF, and .T. (true) with SET EXACT ON.

The setting SET LEXICAL ON has precedence over SET EXACT ON. When SET LEXICAL ON, character comparisons are based on the country specific lexical character values defined by the operating system. The lexical value of one or more characters can be redefined with the function SetLexrule().

Comparison of data values

Values with data type date are compared on a chronological basis.

Comparison of logical values

The value .F. (false) is not equal to the value .T. (true).

Comparison of numeric values

A comparison is based on the sizes of the numeric values.

Examples
The not equal operator (<>,!=,#)
// This example illustrates the results of the not equal operator 
// with various comparison expressions. 
// The character string comparisons show the various possibilities of 
// using SET EXACT and SET LEXICAL. 

PROCEDURE Main 
   SET EXACT OFF 
                                    // character value 
   ? "A"  <> "Z"                    // result: .T. 
   ? "A"  <> "A "                   // result: .T. 
   ? "A " <> "A"                    // result: .F. 
   ? ""   <> "A"                    // result: .T. 
   ? "A"  <> ""                     // result: .F. 
   ? "AB" <> "ABC"                  // result: .T. 
   ? "ABC"<> "AB"                   // result: .F. 

   SET EXACT ON 

   ? "A"  <> "Z"                    // result: .T. 
   ? "A"  <> "A "                   // result: .F. 
   ? "A " <> "A"                    // result: .F. 
   ? ""   <> "A"                    // result: .T. 
   ? "A"  <> ""                     // result: .T. 
   ? "AB" <> "ABC"                  // result: .T. 
   ? "ABC"<> "AB"                   // result: .T. 

   SetLexrule( "ß", "ss" )          // "ß" translates to "ss" 
   ? "gross" <> "groß"              // result: .T. 

   SET LEXICAL ON 
   ? "gross" <> "groß"              // result: .F. 

   ? CtoD("12/31/94") <> ;          // date value 
     CtoD("01/01/95")               // result: .T. 

                                    // logical value 
   ? .F. <> .T.                     // result: .T. 

                                    // numeric value 
   ? 5  <> 10                       // result: .T. 
   ? 10 <> 5                        // result: .T. 

                                    // array 
   ? {1,2,3} <> NIL                 // result: .T. 

RETURN 
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.