Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

Logical Operators


Operator
Description
Example
&&
Logical AND.
Returns 1 whenever both of its operands are true; otherwise, returns 0. Non-zero numerical values, non-null strings, and non-null heap variables (pointers and object references) are considered true, everything else is false.
Operands must be scalars or single-element arrays. The && operator short-circuits; the second operand will not be evaluated if the first is false.

PRINT, 5 && 7

IDL Prints: 1
  

PRINT, 5 && 2

IDL Prints: 1
  

PRINT, 4 && 0

IDL Prints: 0

||
Logical OR.
Returns 1 whenever either of its operands are true; otherwise, returns 0. Uses the same test for "truth" as the && operator.
Operands must be scalars or single-element arrays. The || operator short-circuits; the second operand will not be evaluated if the first is true.

IF ((5 GT 3) || (4 GT 5)) THEN $

   PRINT, 'True'

  
IDL Prints:
True
~
Logical negation.
Returns 1 when its operand is false; otherwise, returns 0.
Uses the same test for "truth" as the && operator.

PRINT, ~ [1, 2, 0]

  
IDL Prints:
0  0  1

 


Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]