Difference between revisions of "Boolean Operators"

From SmartWiki
Jump to: navigation, search
(Created page with '==AND== * The '''AND''' operator takes two operands and evaluates to ''true'' if '''both''' of its operands are true. * Also written as "&&". Example: [True Statement] AND …')
 
 
(8 intermediate revisions by one other user not shown)
Line 2: Line 2:
  
 
* The '''AND''' operator takes two [[operand]]s and evaluates to ''true'' if '''both''' of its operands are true.
 
* The '''AND''' operator takes two [[operand]]s and evaluates to ''true'' if '''both''' of its operands are true.
* Also written as "&&".
+
* Also written as "&&", between the two operands.
 
  Example: [True Statement] AND [False Statement] ...evaluates to... '''FALSE'''
 
  Example: [True Statement] AND [False Statement] ...evaluates to... '''FALSE'''
 +
Example: [True Statement] AND [True Statement] ...evaluates to... '''TRUE'''
  
 
==OR==
 
==OR==
  
* The ''OR'' operator takes two [[operands]] and evaluates to ''true'' if '''either''' of the operands are true.  
+
* The '''OR''' operator takes two [[operand]]s and evaluates to ''true'' if '''either''' of the operands are true.  
* Also written as "||".
+
* Also written as "||", between the two operands.
 +
Example: [True Statement] OR [True Statement] ...evaluates to... '''TRUE'''
 +
Example: [True Statement] OR [False Statement] ...evaluates to... '''TRUE'''
 +
Example: [False Statement] OR [False Statement] ...evaluates to... '''FALSE'''
  
 
==NOT==
 
==NOT==
  
* Reverses the "truthiness" of its operand.  
+
* Reverses the "truthiness" of its [[operand]].  
 
* Also written as "!", preceding its operand.
 
* Also written as "!", preceding its operand.
 +
Example: NOT [True Statement] ...evaluates to... '''FALSE'''
 +
Example: NOT [False Statement] ...evaluates to... '''TRUE'''
  
 +
==See Also==
 +
* [[Advanced Logic]]
 +
* [[Advanced Search]]
  
The and operator takes two operands and evaluates to true if both of its operands are true. Similarly, the or operator takes two arguments and evaluates to true if either of the operands are true. More commonly, you'll see these operators in their symbolic form: && (two ampersands) for the and operator and || (two pipe characters) for the or operator. Though they appear to be the same at first, don't use them interchangeably (see below).
+
[[Category:Variables]]
 
 
In addition to && and ||, there's also a ! or not operator. It's a unary operator (like the negative operator, it precedes its operand) and reverses the truthiness of its operand. Pass it something true and it will evaluate to false. Pass it something false and it will evaluate to true. This operator is not used all that often though, as the == has a != counterpart, >= has <, etc. Even the conditionals have counterparts that have reverse meaning, like if and unless. Using these operators and alternative conditionals is often more clean than using the not operator.
 

Latest revision as of 12:36, 20 October 2017

AND

  • The AND operator takes two operands and evaluates to true if both of its operands are true.
  • Also written as "&&", between the two operands.
Example: [True Statement] AND [False Statement] ...evaluates to... FALSE
Example: [True Statement] AND [True Statement] ...evaluates to... TRUE

OR

  • The OR operator takes two operands and evaluates to true if either of the operands are true.
  • Also written as "||", between the two operands.
Example: [True Statement] OR [True Statement] ...evaluates to... TRUE
Example: [True Statement] OR [False Statement] ...evaluates to... TRUE
Example: [False Statement] OR [False Statement] ...evaluates to... FALSE

NOT

  • Reverses the "truthiness" of its operand.
  • Also written as "!", preceding its operand.
Example: NOT [True Statement] ...evaluates to... FALSE
Example: NOT [False Statement] ...evaluates to... TRUE

See Also