Content deleted Content added
→Examples: Added new example |
m Reverted edits by 60.48.39.68 (talk) (AV) |
||
(37 intermediate revisions by 31 users not shown) | |||
Line 1:
{{Short description|Expression in a computer program}}
In [[computer science]], a '''Boolean expression''' (also known as '''logical expression''') is an [[Expression (programming)|expression]] used in
| last1 = Gries | first1 = David | author1-link = David Gries
| last2 = Schneider | first2 = Fred B. | author2-link = Fred B. Schneider
Line 11 ⟶ 12:
| year = 1993}}.</ref>
Boolean expressions correspond to [[propositional formula]]s in logic and are
| last = van Melkebeek | first = Dieter
| isbn = 9783540414926
Line 23 ⟶ 24:
==Boolean operators==
Most [[programming language]]s have the Boolean operators [[Logical disjunction|OR]], [[Logical conjunction|AND]] and [[Negation|
| last1 = Brogden | first1 = William B.
| last2 = Green | first2 = Marcus
Line 31 ⟶ 32:
| title = Java 2 Programmer
| url = https://books.google.com/books?id=24nPZw9Wsf4C&pg=PA45
| year = 2003}}.</ref> In the mathematical literature the symbols used are often "+" ([[Plus sign|plus]]), "'''·'''" ([[Full stop|dot]]) and [[overbar]], or "∨" (
Some languages, e.g., [[Perl]] and [[Ruby (programming language)|Ruby]], have two sets of Boolean 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 Boolean 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]] Boolean operators. These operators use a [[lazy evaluation]], that is, if the value of the expression can be determined from the left hand Boolean expression then they do not evaluate the right hand Boolean 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==
*The expression
*The expression
*
*Of course, most Boolean expressions will contain at least one variable ({{code|X > 3}}), and often more ({{code|X > Y}}).▼
▲*Of course, most Boolean expressions will contain at least one variable (X > 3), and often more (X > Y).
==See also==
*[[Expression (computer science)]]
*[[Expression (mathematics)]]
*[[Boolean function]]
==References==
|