It is named after George Boole, who first defined an algebraic system of logic in the mid 19th century.
The C programming language uses an integer type, where relational expressions like i > j and logical expressions connected by && and || are defined to have value 1 if true and 0 if false, whereas the test parts of if, while, for, etc., treat any non-zero value as true.
One of the earliest programming languages to provide an explicit BOOLEAN data type is ALGOL 60 (1960) with values true and false and logical operators denoted by symbols '
Due to input device and character set limits on many computers of the time, however, most compilers used alternative representations for many of the operators, such as AND or 'AND'.
This approach with BOOLEAN as a built-in (either primitive or otherwise predefined) data type was adopted by many later programming languages, such as Simula 67 (1967), ALGOL 68 (1970),[3] Pascal (1970), Ada (1980), Java (1995), and C# (2000), among others.
FORTRAN IV (1962), however, follows the ALGOL 60 example by providing a Boolean data type (LOGICAL), truth literals (.TRUE.
For convenience, most modern dialects of Lisp predefine the atom t to have value t, so that t can be used as a mnemonic notation for true.
In Scheme, for example, the false value is an atom distinct from the empty list, so the latter is interpreted as true.
Common Lisp, on the other hand, also provides the dedicated boolean type, derived as a specialization of the symbol.
[5] The language Pascal (1970) popularized the concept of programmer-defined enumerated types, previously available with different nomenclature in COBOL, FACT and JOVIAL.
By definition, all comparisons, logical operations, and conditional statements applied to and/or yielded Boolean values.
In contrast, converting between Booleans and integers (or any other types) still required explicit tests or function calls, as in ALGOL 60.
The language guarantees that any two true values will compare equal (which was impossible to achieve before the introduction of the type).
A bool value can be implicitly converted to any integral type, with false becoming 0 and true becoming 1.
Casting an expression to bool means testing for 0 or !=0 for arithmetic types, and null or !=null for pointers or references.
Objective-C also has a separate Boolean data type BOOL, with possible values being YES or NO, equivalents of true and false respectively.
The number 0, the strings "0" and "", the empty list (), and the special value undef evaluate to false.
However, apart from TRUE and FALSE, these operators can also yield a third state, called UNKNOWN, when comparison with NULL is made.
The SQL92 standard introduced IS (NOT) TRUE, IS (NOT) FALSE, and IS (NOT) UNKNOWN operators which evaluate a predicate, which predated the introduction of Boolean type in SQL:1999.
[12][13] This has caused some controversy because the identification subjects UNKNOWN to the equality comparison rules for NULL.
For example, in Microsoft SQL Server, Boolean value is not supported at all, neither as a standalone data type nor representable as an integer.
It shows the error message "An expression of non-Boolean type specified in a context where a condition is expected" if a column is directly used in the WHERE clause, e.g.
The BIT data type, which can only store integers 0 and 1 apart from NULL, is commonly used as a workaround to store Boolean values, but workarounds need to be used such as UPDATE t SET flag = IIF(col IS NOT NULL, 1, 0) WHERE flag = 0 to convert between the integer and Boolean expression.
[25] The Tableau INT() function converts a Boolean to a number, returning 1 for True and 0 for False.
[27] In some programming languages, any expression can be evaluated in a context that expects a Boolean data type.
Typically (though this varies by programming language) expressions like the number zero, the empty string, empty lists, and null are treated as false, and strings with content (like "abc"), other numbers, and objects evaluate to true.