Shiny Language Reference

Language Reference > Logical Operators


Logical Operators

or

and

not

 

Logical Operators

Logical operators perform actions based on a boolean value, or the boolean result of a test. There are 3 logical operators:

or Evaluates 2 boolean tests, returns True if one or both tests return True
 
Examples:  
True or False Returns True
 
True or True Returns True
 
False or False Returns False
 
a or b If a or b are True, returns True. If both are False, returns false

 

and Evaluates 2 boolean tests, returns True only if both tests return true
 
Examples:  
True and False Returns False
 
True and True Returns True
 
False and False Returns False
 
a and b If a and b are both True, returns True. Otherwise returns False

 

not Inverse operator, if the rvalue is True it returns False and vice versa
 
Examples:  
not False Returns True
 
not True Returns False
 
not a If a is True, returns False. If a is False, returns True

 

Note that the NOT operator only takes an rvalue.

 

Alternate Syntax

Shiny supports dual syntax for logical operators. The following symbolic operators are identical to their textual counterparts, but will be more familiar to C/C++, Java, PHP and similar developers.

Operator Equivalent to Performs
|| or Logical OR
&& and Logical AND
! not Logical NOT

 

Examples

bool Result;

int a = 1;
int b = 9;

// Result will be True, a is less than b
Result = a < b;

// Result will be True, b doesn't equal 0 but a is less than b

Result = a < b or b == 0;

// Result will be False, both conditions do not evaluate to True

Result = a < b and b == 0;

// Result will be False, a is less than b but the result is inversed

Result = not a < b;