In programming languages that have a built-in Boolean data type, such as Pascal and Java, the comparison operators such as '>' and '≠' are usually defined to return a Boolean value. Also, conditional and iterative commands may be defined to test Boolean-valued expressions.
Languages without an explicit Boolean data type, like C and Lisp, may still represent truth values it by some other data type. Lisp uses an empty list for false, and any other value for true. C uses an integer type, with false represented as the zero value, and true as any non-zero value (such as 1 or -1). Indeed, a Boolean variable may be regarded (and be implemented) as a numerical variable with a single binary digit (bit), which can store only two values.
Most programming languages, even those that do not have an explicit Boolean type, have support for Boolean algebra operations such as conjunction (
*), disjunction (
+), equivalence (
==), exclusive or/non-equivalence (
!=), and not (
In some languages, the Boolean data type is defined to include more than two truth values. For instance the ISO SQL 1999 standard defined a Boolean value as being either true, false, or unknown (SQL null). Although this convention defies the law of excluded middle, it is often useful in programming.
One of the earliest languages to provide an explicit Boolean data type was Algol 60 (1960) with values true and false and logical operators denoted by symbols '' (and), '' (or)', ' (implies), '' (equivalence), and '' (not). Due to input device limitations of the time, however, most compilers used alternative representations for the latter, such as
'AND'. This approach ("Boolean is a separate built-in primitive data type") was adopted by many later languages, such as ALGOL 68 (1970) , Java, and C#.
The first version of FORTRAN (1957) and its successor FORTRAN II (1958) did not have logical values or operations; even the conditional
IF statement took an arithmetic expression and branched to one of three locations according to its sign. FORTRAN IV (1962), however, followed the Algol 60 example by providing a Boolean data type (
LOGICAL), truth literals (
.FALSE.), Boolean-valued numeric comparison operators (
.GT., etc.), and logical operators (
FORMAT statements, a specific control character ('
L') was provided for the parsing or formatting of logical values.
The Lisp programming language (1958) never had a built-in Boolean data type. Instead, conditional constructs like
cond assume that the logical value "false" is represented by the empty list
(), which is defined to be the same as the special atom
NIL; whereas any other s-expression is interpreted as "true". For convenience, most modern dialects of Lisp predefine the atom
t to have value
t, so that one can use
t as a mnemonic notation for "true". This approach ("any value can be used as a Boolean value") was retained in most Lisp dialects (Common Lisp, Scheme, Emacs Lisp), and similar models were adopted by many scripting languages; although which values are interpreted as "false" and which are "true" vary from language to language. In Scheme, for example, the "false" value is an atom distinct from
nil, so the latter is interpreted as "true". In Python, a numeric value of zero (integer or fractional), the null value (
None), and empty containers (i.e. strings, lists, sets, etc.) are considered boolean false; all other values are considered boolean true by default. In Ruby programming language, on the other hand, only the null object and a special
false object are "false", everything else (including the integer 0) is "true".
The initial standards for the C programming language (1972) provided no Boolean type; and, to this day, Boolean values are commonly represented by integers (
ints) in C programs. The comparison operators ('
==', etc.) are defined to return a signed integer (
int) result, either zero (for false) or 1 (for true). The same convention is assumed by the logical operators ('
!', etc.) and condition-testing statements ('
while'). Thus logical values can be stored in integer variables, and used anywhere integers would be valid, including in indexing, arithmetic, parsing, and formatting. This approach ("Boolean values are just integers") was retained in all later versions of C. Some of its dialects, like C99 and Objective C, provide standard definitions of a Boolean type as a synonym of
int and macros for "false" and "true" as 0 and 1, respectively. Visual Basic uses a similar approach. C++ has a separate Boolean data type (
'bool'), but with automatic conversions from scalar and pointer values that are very similar to those of C. This approach was adopted also by many later languages, especially by some scripting ones such as Awk and Perl. One problem with this approach is that the tests
if(t) are not equivalent.
The Pascal programming language (1978) introduced the concept of programmer-defined enumerated types. A built-in
Boolean data type was then provided as a predefined enumerated type with values
TRUE. By definition, all comparisons, logical operations, and conditional statements applied to and/or yielded
Boolean values. Otherwise, the
Boolean type had all the facilities which were available for enumerated types in general — such as ordering and use as indices. On the other hand, the conversion between
Booleans and integers (or any other types) still required explicit tests or function calls, as in Algol 60. This approach ("Boolean is an enumerated type") was adopted by most later languages which had enumerated types, such as Modula, Ada and Haskell.
After enumerated types ('
enum's) were added to the ANSI version of C (1989), many C programmers got used defining their own Boolean types as such, for readability reasons. However, enumerated types are equivalent to integers according to the language standards; so the effective identity between Booleans and integers is still valid for most C programs and libraries.
In recent versions of Python, user-defined objects may specify their truth value by providing a
Boolean object class which can be used as a wrapper for storing and handling its two Boolean values. However, paradoxically, such a Boolean object will be automatically interpreted as "true" in Boolean contexts, even if its stored value is "false".
As of the 1999 standard, SQL specified a Boolean data type with four possible values: true, false, unknown or null. However, vendors could choose to equate the last two values.. Because of this inconsistency most SQL implementations (with the notable exception of Postgresql) use other data types (like bit, byte, and character) to simulate Boolean values.