Boolean expression: Difference between revisions

Content deleted Content added
Boolean operators: short-circuit operators
Boolean operators: Misc. minor touches
Line 24:
 
==Boolean operators==
Most [[programming language]]s have the Boolean operators [[Logical disjunction|OR]], [[Logical conjunction|AND]] and [[Negation|NOT]]; in [[C (programming language)|C]] and some newer[[List of C-family programming languages|languages inspired by it]], these are represented by "||" (double pipe character), "&&" (double [[ampersand]]) and "!" ([[Exclamation mark|exclamation point]]) respectively, while the corresponding [[bitwise operation]]s are represented by "|", "&" and "~" (tilde).<ref>E.g. for [[Java (programming language)|Java]] see {{citation
| last1 = Brogden | first1 = William B.
| last2 = Green | first2 = Marcus
Line 34:
| year = 2003}}.</ref> In the mathematical literature the symbols used are often "+" ([[Plus sign|plus]]), "'''·'''" ([[Full stop|dot]]) and [[overbar]], or "∨" ([[Descending_wedge|vel]]), "∧" ([[Wedge_(symbol)|et]]) and "¬" ([[Negation|not]]) or "′" (prime).
 
Some languages, e.g., [[Perl]] and [[Ruby (programming language)|Ruby]], have two sets of booleanBoolean operators, with identical functions but different precedence. Typically these languages use '''and''', '''or''' and '''not''' for the lower precedence operators.
 
Some programming languages derived from [[PL/I]] have a bit string type and use BIT(1) rather than a separate booleanBoolean type. In those languages the same operators serve for boolean operations and bitwise operations. The languages represent OR, AND, NOT and EXCLUSIVE OR by "|", "&", "¬" (infix) and "¬" (prefix).
 
===Short-circuit operators===
{{Main|Short-circuit evaluation}}
Some programming languages, e.g., [[Ada (programming language)|Ada]], have [[Short-circuit evaluation|short-circuit]] booleanBoolean operators. These operators use a [[lazy evaluation]], that is, if the value of the expression can be determined from the left hand booleanBoolean expression then they do not evaluate the right hand booleanBoolean expression. As a result, there may be [[Side effect (computer science)|side effects]] that only occur for one value of the left hand operand.
 
==Examples==