Boolean values: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 1:
{{task|Basic language learning}}
[[Category:Simple]]
{{task|Basic language learning}}
 
;Task:
Line 11:
*   [[Logical operations]]
<br><br>
=={{header|8th}}==
 
In 8th, any non-zero number is true, as is the specific boolean value 'true'. Everything else evaluates as 'false' (including the boolean value, 'false')
=={{header|11l}}==
11l defines a built-in data type <code>Bool</code>, which has two values represented by the constants <code>0B</code> and <code>1B</code>.
 
=={{header|360 Assembly}}==
The are no TRUE or FALSE constants in 360 Assembly; but an often used convention is :
<syntaxhighlight lang="360asm">FALSE DC X'00'
TRUE DC X'FF'</syntaxhighlight>
=={{header|6502 Assembly}}==
There are no built-in true or false constants, but the functionality can be easily replicated with zero or nonzero values (or any two values which can cause a mutually exclusive branch condition, such as with <code>#$7f</code> and <code>#$80</code> and using <code>BMI</code>/<code>BPL</code>)
 
=={{header|68000 Assembly}}==
There are no built-in true or false constants, but the functionality can be easily replicated with zero or nonzero values (or any two values which can cause a mutually exclusive branch condition, such as with <code>#$7f</code> and <code>#$80</code> and using <code>BMI</code>/<code>BPL</code>)
 
=={{header|8051 Assembly}}==
A single bit represents true or false. By convention, 0 (cleared) is false, 1 (set) is true.
In the following, "bit" represents the direct address of any of the 256 directly accessible bits.
<syntaxhighlight lang="asm">clr bit ; clears
setb bit ; sets</syntaxhighlight>
=={{header|68000 Assembly}}==
 
There are no built-in true or false constants, but the functionality can be easily replicated with zero or nonzero values (or any two values which can cause a mutually exclusive branch condition, such as with <code>#$7f</code> and <code>#$80</code> and using <code>BMI</code>/<code>BPL</code>)
=={{header|8th}}==
In 8th, any non-zero number is true, as is the specific boolean value 'true'. Everything else evaluates as 'false' (including the boolean value, 'false')
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang=AArch64"aarch64 Assemblyassembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program boolean.s */
Line 88 ⟶ 82:
.include "../includeARM64.inc"
</syntaxhighlight>
 
=={{header|ACL2}}==
Same as [[Common Lisp|Boolean Values#Common Lisp]].
 
=={{header|Action!}}==
<syntaxhighlight lang=Action"action!">PROC Test(BYTE v)
PrintF("Variable v has value %B%E",v)
IF v THEN
Line 144 ⟶ 136:
Condition IF v#0 is satisfied.
</pre>
 
=={{header|Ada}}==
[[Ada]] has a predefined discrete type with the specification:
<syntaxhighlight lang=Ada"ada"> type Boolean is (False, True);</syntaxhighlight>
with Boolean lattice and relational operations defined on it. See [http://www.adaic.org/standards/1zrm/html/RM-A-1.html RM A.1].
 
=={{header|ALGOL 68}}==
{{trans|python}}
Line 158 ⟶ 148:
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - note: null char is missing, AND the C generated is won't compile, so some conversions are missing from RS}}
ALGOL 68 Enforces strong typing and so has few default coercions. The appropriate operators must be used to convert to and from '''bool'''[ean] and the following code demonstrates principle conversions:
<syntaxhighlight lang="algol68">BOOL f = FALSE, t = TRUE;
[]BOOL ft = (f, t);
STRING or = " or ";
Line 215 ⟶ 205:
</pre>
Note: The '''string''' '''repr'''[esentation] of '''false''' and '''true''' are defined by the variables ''flop'' and ''flip'' respectively.
 
=={{header|ALGOL W}}==
The boolean type is called logical in Algol W - the values are represented by the keywords true and false. Numbers, strings etc. cannot be used where logical values are required.
 
=={{header|APL}}==
0 and 1 are used for boolean types in APL (as in J below).
<syntaxhighlight lang=APL"apl">
1 ^ 1
1
Line 227 ⟶ 215:
0
</syntaxhighlight>
 
=={{header|AppleScript}}==
AppleScript has built-in boolean keywords <code>true</code> and <code>false</code>. Numbers do not work in place of boolean expressions, but they do coerce to and from.
 
<syntaxhighlight lang=AppleScript"applescript">1 > 2 --> false
not false --> true
 
Line 241 ⟶ 228:
AppleScript also has constants <code>yes</code> and <code>no</code>, which coerce easily to boolean values. They have little practical value in AppleScript except if one wishes to use them as arguments in place of boolean values for novelty's sake. They are interchangeable with boolean values as parameters in AppleScriptObjC (not demonstrated here).
 
<syntaxhighlight lang=AppleScript"applescript">{yes as boolean, no as boolean}
--> {true, false}</syntaxhighlight>
 
Line 248 ⟶ 235:
Finally, AppleScript also includes keywords <code>with</code> and <code>without</code>, used in declaring parameters for and sending parameters of boolean nature to handlers. They are synonymous with <code>true</code> and <code>false</code>, respectively, and the compiler will sometimes perform the substitution at compile time.
 
<syntaxhighlight lang=AppleScript"applescript">sortItems from L given reversal : true</syntaxhighlight>
 
gets compiled immediately to become:
 
<syntaxhighlight lang=AppleScript"applescript">sortItems from L with reversal</syntaxhighlight>
 
However, the equivalent call to the handler utilising <code>yes</code>, whilst accepted readily in place of its boolean counterpart, is left alone by the compiler:
 
<syntaxhighlight lang=AppleScript"applescript">sortItems from L given reversal:yes</syntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang=ARM"arm Assemblyassembly">
/* ARM assembly Raspberry PI */
/* program areaString.s */
Line 328 ⟶ 314:
 
</syntaxhighlight>
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">a: true
b: false
 
Line 342 ⟶ 327:
<pre>yep
yep</pre>
 
=={{header|AutoHotkey}}==
When an expression is required to evaluate to true or false (such as an <code>IF</code>-statement), a blank or zero result is considered false and all other results are considered true. Operators such as <code>NOT</code>/<code>AND</code>/<code>OR</code>/<code>></code>/<code>=</code>/<code><</code> automatically produce a true or false value: they yield 1 for true and 0 for false. A variable can be used to hold a false value simply by making it blank or assigning 0 to it. The words 'true' and 'false' are built-in variables containing 1 and 0. They can be used to make a script more readable.
 
=={{header|Avail}}==
 
While Avail has many methods for handling booleans, <code>boolean</code> itself is simply an enumeration type of the atoms <code>true</code> and <code>false</code>. This enumeration and these atoms are only special ''by convention'' of being used for the logical operations provided by the standard library. It would be perfectly possible to define an entirely new boolean system with new types and atoms (or values).
 
=={{header|AWK}}==
 
Line 358 ⟶ 340:
In the following example we use zero for false, and one for true to assign boolean values. However, this is just a convention, so other values may also have been used:
 
<syntaxhighlight lang="awk">BEGIN {
# Do not put quotes round the numeric values, or the tests will fail
a = 1 # True
Line 376 ⟶ 358:
 
}</syntaxhighlight>
 
=={{header|Axe}}==
In Axe, there are no keywords for true and false. Any expression that evaluates to zero is considered false, and any expression that evaluates to non-zero is considered true. Unlike other languages, there is no canonical value for true (e.g. 1).
 
=={{header|BASIC}}==
Most BASICs have no keywords for true and false. Boolean expressions evaluate to 0 when false, and a non-zero value (traditional versions of basic use a value of one, although some variants use a value of negative one) when true. Numbers also work in place of boolean expressions following those rules.
 
<syntaxhighlight lang="gwbasic">10 LET A%=0
20 LET B%=NOT(A%)
30 PRINT "THIS VERSION OF BASIC USES"
Line 397 ⟶ 377:
==={{header|Applesoft BASIC}}===
IF statement condition treats any non-zero numeric value as true. Comparison operators evaluate to 1 (true) or 0 (false).
Examples:<syntaxhighlight lang=ApplesoftBASIC"applesoftbasic">? 2 = 3
? 2 = 2
IF 7 THEN ?"HELLO"</syntaxhighlight>
Line 407 ⟶ 387:
 
==={{header|BaCon}}===
<syntaxhighlight lang="qbasic">' Boolean TRUE and FALSE are non-zero and zero constants
a = TRUE
b = FALSE
Line 430 ⟶ 410:
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">
' BASIC256 used numbers to represent true and false
' values. Zero is false and anything else is true.
Line 441 ⟶ 421:
 
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbcbasic"> REM BBC BASIC uses integers to represent Booleans; the keywords
REM FALSE and TRUE equate to 0 and -1 (&FFFFFFFF) respectively:
Line 450 ⟶ 430:
Commodore BASIC evaluates any non-zero number for TRUE&mdash;but is typically represented as 16-bit signed integer value of -1 or $FFFF&mdash;and zero evaluates to FALSE.
 
<syntaxhighlight lang="gwbasic">10 f%=("z"="a") : t%=not f% : rem capture a boolean evaluation
15 print chr$(147);chr$(14);
20 print "True is evaulated as:";t%
Line 493 ⟶ 473:
 
Sample code:
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Dim i As Integer = 23
Line 522 ⟶ 502:
==={{header|Microsoft Small Basic}}===
Microsoft Small Basic has two constants: <code>"True"</code> and <code>"False"</code>.<br>
<syntaxhighlight lang="smallbasic">If c Then
notc = "False"
Else
Line 532 ⟶ 512:
In addition to what's noted above under [[#BASIC|BASIC]], [[PowerBASIC for Windows]] and [[PowerBASIC Console Compiler]] have the <code>ISTRUE</code> and <code>ISFALSE</code> functions. According to the help file, they "return the logical truth or falsity of a given expression". ([[PowerBASIC]] lacks a boolean data type, so the usual practice is to use integers in [[PB/DOS]], and longs in [[PB/CC]] and [[PB/Win]].)
 
<syntaxhighlight lang="powerbasic">DIM x AS LONG
x = ISTRUE(1 = 1) ' returns -1
x = ISTRUE(1 = 0) ' returns 0
Line 544 ⟶ 524:
QBasic, QuickBASIC, VB-DOS and GW-BASIC doesn't have a Boolean type. What it does is to take 0 as False, and any other value as True. The easiest way in QBASIC, QuickBASIC and VB-DOS is to create False and True constants of type Integer and, then, use them as needed:
 
<syntaxhighlight lang=QBASIC"qbasic">
CONST FALSE=0
CONST TRUE = Not FALSE
Line 553 ⟶ 533:
In GW-BASIC you can create a variable called FALSE% and other called TRUE% and do the same. Nevertheless, is more sure to create functions in order to avoid the value to be manipulated:
 
<syntaxhighlight lang=QBASIC"qbasic">
10 DEF FNFALSE = 0
20 DEF FNTRUE = NOT FNFALSE
Line 562 ⟶ 542:
==={{header|Run BASIC}}===
Basically 0 is false and 1 is true
<syntaxhighlight lang="runbasic">if 1 then print "1 is true"
if not(0) then print "0 is false"
if 1 < 2 then print "1 < 2 TRUE"
Line 580 ⟶ 560:
 
==={{header|True BASIC}}===
<syntaxhighlight lang="basic">
!True BASIC maneja correctamente las expresiones booleanas,
!Pero no tiene un tipo booleano.
Line 607 ⟶ 587:
==={{header|uBasic/4tH}}===
In conditionals, zero is false, non-zero is true. Note that '''=''' is not only used for assignment, it is also a fully qualified logical operator, so it is easy to assign a true boolean to a variable.
<syntaxhighlight lang="text">t = 1 = 1
f = 0 = 1
 
Line 617 ⟶ 597:
 
==={{header|Yabasic}}===
<syntaxhighlight lang=Yabasic"yabasic">
// Yabasic usa números para representar los valores true y false
// Las constantes incorporadas true y false representan uno y cero respectivamente.
Line 633 ⟶ 613:
<br>When converting an integer to a boolean, <code>0</code> is <code>False</code> and anything not equal to <code>0</code> is
 
<syntaxhighlight lang="vb">Dim x As Boolean
x = IIf(Int(Rnd * 2), True, False)
MsgBox x</syntaxhighlight>
 
=={{header|Batch File}}==
The closest thing to Boolean values in batch files is using <code>if defined</code>.
Line 643 ⟶ 622:
You can make a variable false by clearing its value <code>set "var="</code>.
 
<syntaxhighlight lang="dos">
@echo off
 
Line 670 ⟶ 649:
b is false
</pre>
 
=={{header|bc}}==
POSIX bc doesn't define Boolean values (i.e. it's up to the programmer which values represent false and true).
 
In GNU bc, 0 is false and any other value is true (but the result of a boolean expression will always be 1 if it is true).
 
=={{header|Befunge}}==
Zero is false, non-zero is true. This is only used by the horizontal and vertical switch operators (<code>_</code> and <code>|</code>).
 
=={{header|BQN}}==
 
Line 695 ⟶ 671:
!0
ERROR</pre>
 
=={{header|Bracmat}}==
Bracmat operates with success and failure instead of true and false. Success and failure play the same role as true and false in conditional tests, but they are not values like true and false. Instead, success and failure are properties of expressions in addition to values. The simplest failing expression is the atomic expression <code>~</code>. The simplest succeeding atomic expression is the empty string <code>""</code> (or <code>()</code>). A slightly more complex failing expression is <code>1+1:3</code>, which postulates that <code>3</code> matches the result of adding <code>1</code> and <code>1</code>, while <code>1+1:2</code> of course succeeds.
 
=={{header|Brainf***}}==
Zero is false, non-zero is true. This is only used by the loop brackets (<code>[</code> and <code>]</code>).
 
=={{header|C}}==
In C, a value which is equal to 0 is false, while a value which is not equal to 0 is true. Relational and logical operators evaluate to 0 for false and 1 for true. Any of the following can be used:
Line 710 ⟶ 683:
* in C99, the boolean type <code>bool</code> (defined in header <tt><stdbool.h></tt>), where <code>true</code> gives true and <code>false</code> gives false
* in C99, any [[Complex numbers|complex number]] type, where 0 (0 real and 0 imaginary) gives false, anything else gives true
 
=={{header|C sharp|C#}}==
In C#, there are the reserved keywords <code>true</code> and <code>false</code>. Variables to hold these values are declared as either <code>bool</code> or <code>Boolean</code>. These types are identical, as <code>bool</code> is just shorthand for <code>Boolean</code>. The collection type <code>BitArray</code> returns its values as <code>Boolean</code>, packing 8 values into each byte (In contrast, the <code>Boolean</code> type uses the entire byte for one value).
Line 717 ⟶ 689:
So, when applied to <code>bool</code>, we have a <code>bool?</code> type that supports 3 values: <code>true</code>, <code>false</code> and <code>null</code>. This can be useful for some applications where the value can be undefined or missing.
 
<syntaxhighlight lang="csharp">bool? value = null</syntaxhighlight>
 
Unlike C/C++, there is no conversion in C# between other types and <code>Boolean</code>.
 
=={{header|C++}}==
In C++, there are the constants <code>true</code> and <code>false</code> to represent those values. However, there are numerous implicit conversions to <code>bool</code>, therefore in conditions (and other contexts expecting boolean values), any of the following can be used:
Line 728 ⟶ 699:
* any pointer type, where the null pointer gives false and any other pointer gives true
* any user-defined type with an implicit conversion operator either to <code>bool</code> or to a built-in type which itself can be converted to <code>bool</code> (i.e. any of the above). The C++ standard library contains one such implicit conversion: the implicit conversion of a stream <code>s</code> to <code>bool</code> gives <code>!s.fail()</code>
 
=={{header|Clean}}==
 
The standard library defines a data type <code>Bool</code>, which has exactly two members:
 
<syntaxhighlight lang="clean">::Bool = False | True</syntaxhighlight>
 
In addition to all the functionality of any other Clean algebraic data type (e.g. [[pattern matching]]), and the specified derived typeclass instances, the built-in guard (“<code>|</code>”) and <code>if</code> syntaxes use Bool.
 
As with any other Clean data type, there are no automatic conversions of other types to Bool.
 
=={{header|Clojure}}==
The boolean constants are ''true'' and ''false''. In a conditional context, the only false values are ''false'' and ''nil'' -- every other value is true.
 
=={{header|CMake}}==
<syntaxhighlight lang="cmake">foreach(var 1 42 ON yes True y Princess
0 OFF no False n Princess-NOTFOUND)
if(var)
Line 769 ⟶ 737:
 
Scripts that want <code>if(TRUE)</code> should require CMake 2.8; do refer to [http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0012 cmake --help-policy CMP0012].
 
=={{header|COBOL}}==
===Booleans===
Booleans are defined as any data item having a <code>PICTURE</code> made up of ones.
<syntaxhighlight lang="cobol"> 01 some-bool PIC 1 BIT.</syntaxhighlight>
 
The boolean literals <code>B"1"</code> and <code>B"0"</code> represent true and false, respectively.
Line 779 ⟶ 746:
===Conditions===
Prior to COBOL 2002, there was no boolean data type, only ''condition names'' which could be used in conditional expressions. Condition names are subordinate to another data item, have the level-number 88, and are defined with the value(s) which their parent data item must have for them to be set to true. They can be defined like so:
<syntaxhighlight lang="cobol"> 01 X PIC 9.
88 X-Is-One VALUE 1.
88 X-Is-Even VALUE 0 2 4 6 8.
Line 785 ⟶ 752:
 
Conditions can be <code>SET</code> to <code>TRUE</code> or <code>FALSE</code>. Setting a condition to <code>TRUE</code> will move the (first) value in the <code>VALUE</code> clause to the parent data item. In COBOL 2002, an optional <code>FALSE</code> clause was added which allowed the condition to be <code>SET</code> to <code>FALSE</code> and consequently set the parent data item to the specified value in the clause. A <code>FALSE</code> clause can only have one value. An example of conditions in action:
<syntaxhighlight lang="cobol"> PROGRAM-ID. Condition-Example.
 
DATA DIVISION.
Line 820 ⟶ 787:
Foo is not zero, it is 1.
</pre>
 
=={{header|CoffeeScript}}==
CoffeeScript is largely based on JavaScript, but that may only serve to confuse you. Your best bet is to learn all the cases:
 
<syntaxhighlight lang="coffeescript">
h1 = {foo: "bar"}
h2 = {foo: "bar"}
Line 854 ⟶ 820:
]
</syntaxhighlight>
 
=={{header|Common Lisp}}==
The only value in Common Lisp that is false is the symbol <code>nil</code>; all other values are true. The symbol <code>t</code> is the canonical true value.
Line 861 ⟶ 826:
 
For more information, follow the links from [http://www.lispworks.com/documentation/HyperSpec/Body/t_ban.htm CLHS: Type BOOLEAN].
 
=={{header|Component Pascal}}==
<syntaxhighlight lang="oberon2">
VAR
b,c: BOOLEAN;
Line 871 ⟶ 835:
...
</syntaxhighlight>
 
=={{header|Crystal}}==
Crystal uses the "truthiness" of a value to determine whether or not to execute the body of an <code>if</code>, <code>unless</code>, <code>while</code>, or <code>until</code> block.
Line 877 ⟶ 840:
As mentioned in the [https://crystal-lang.org/reference/syntax_and_semantics/truthy_and_falsey_values.html language reference], the values <code>nil</code> and <code>false</code>, as well as null pointers are "falsey", all other values are truthy
 
<syntaxhighlight lang="ruby">if false
puts "false"
elsif nil
Line 886 ⟶ 849:
puts "finally true!"
end</syntaxhighlight>
 
=={{header|D}}==
In D, there are constants <code>false</code> and <code>true</code> to represent their respective values (that also implicitly convert to 0 and 1).
Line 896 ⟶ 858:
* Any class reference type, using the "is" operator, the null reference gives false and any other reference gives true;
* Any user-defined type with an implicit conversion operator (opCast) either to bool or to a built-in type which itself can be converted to bool.
 
=={{header|Dc}}==
In dc there are no built in boolean values or functions.
Adopting the way C codes them appears to be a good idea: <code>0=FALSE</code> and <code>1=TRUE</code>.
 
=={{header|Delphi}}==
In addition to the types defined by [[#Object Pascal|Object Pascal]], Delphi defines the type <code>Bool</code>.
 
=={{header|DWScript}}==
The standard <code>Boolean</code> type has two values: <code>True</code> and <code>False</code>, with <code>Ord(False) = 0</code> and <code>Ord(True) = 1</code>.
 
=={{header|Dyalect}}==
 
Dyalect has a standard <code>Bool</code> type with two values: <code>true</code> and <code>false</code>. Other types in Dyalect support implicit conversion to booleans. All values except <code>false</code> and <code>nil</code> are converted to <code>true</code>.
 
=={{header|Dylan}}==
<syntaxhighlight lang=Dylan"dylan">#t // <boolean> true
#f // <boolean> false</syntaxhighlight>
For the purpose of conditional statements, all objects other than <tt>#f</tt> evaluate to true.
 
=={{header|Déjà Vu}}==
 
Déjà Vu has <code>true</code> and <code>false</code>, two numbers that are equal to 1 and 0 respectively. Every object has a truth value. The only falsy things are numbers equal to zero, empty lists and dictionaries, and zero-length strings and blobs.
 
=={{header|E}}==
 
E defines two basic objects <code>true</code> and <code>false</code>, and the <code>boolean</code> [http://wiki.erights.org/wiki/Guard guard] which accepts them. All builtin operations which take booleans (e.g. the <code>if</code> control structure) coerce the input to boolean.
 
<syntaxhighlight lang="e">? if (true) { "a" } else { "b" }
# value: "a"
 
Line 935 ⟶ 890:
No objects in the standard library coerce to boolean, but user-written objects may choose to do so; they can then be used in place of booleans.
 
<syntaxhighlight lang="e">? def bowlian {
> to __conformTo(guard) {
> if (guard == boolean) { return true }
Line 942 ⟶ 897:
> if (bowlian) { "a" } else { "b" }
# value: "a"</syntaxhighlight>
 
=={{header|EchoLisp}}==
"All that which is not false is true" - Attribué à L. Wittgenstein - The only false value is the boolean #f. '''All''' other objects, including the empty list or null or 0 ..- evaluate to #t = true.
<syntaxhighlight lang="scheme">
(not #t) → #f
(not #f) → #t
Line 951 ⟶ 905:
(not 0) → #f
</syntaxhighlight>
 
=={{header|EGL}}==
In EGL boolean is a primitive type, however it acts the same as an integer (type int). A boolean and an int accept integer values aswel as true and false keywords (which represent resp. 1 and 0). A boolean is always true except when it has value 0 (or keyword false).
A boolean can be converted to a string ("true" or "false") using StrLib.booleanAsString(boolean);
 
<syntaxhighlight lang=EGL"egl">
myBool boolean = 0;
SysLib.writeStdout("myBool: " + StrLib.booleanAsString(myBool));
Line 992 ⟶ 945:
myInt: true
</pre>
 
=={{header|Elena}}==
ELENA uses the system'BaseBoolValue class, which has two singleton sub-classes: system'true and system'false. E.g. an expression like 5 == 5 returns system'true.
There is a Boolean variable : system'Boolean.
 
=={{header|Elixir}}==
Elixir utilizes Erlang's definition of boolean types; they're defined as the atoms <tt>:true</tt> and <tt>:false</tt>. No other type is equal to true or false.
<syntaxhighlight lang=Elixir"elixir">
iex(1)> true === :true
true
Line 1,009 ⟶ 960:
 
nil (also defined as an atom, <tt>:nil</tt>) is not equal to false.
<syntaxhighlight lang=Elixir"elixir">
iex(4)> nil === :nil
true
Line 1,015 ⟶ 966:
false
</syntaxhighlight>
 
=={{header|Elm}}==
<syntaxhighlight lang=Elm"elm">
--True and False directly represent Boolean values in Elm
--For eg to show yes for true and no for false
Line 1,062 ⟶ 1,012:
div [] [ text ( toString expr ++ "-->" ++ toString(evaluate expr) ) ]
--END</syntaxhighlight>
 
=={{header|Emacs Lisp}}==
Symbol <code>nil</code> is false and symbol <code>t</code> is true. Both are self-evaluating, being variables whose value is their own symbol. See [http://www.gnu.org/software/emacs/manual/html_node/elisp/nil-and-t.html the elisp manual] for more.
 
In an <code>if</code> and similar, <code>nil</code> is false and anything else is true. To make that clear docstrings etc say "non-nil" for true. (See last item in [http://www.gnu.org/software/emacs/manual/html_node/elisp/Documentation-Tips.html elisp manual documentation tips].)
 
=={{header|Erlang}}==
Erlang doesn't technically define boolean types. Instead, the atoms <tt>true</tt> and <tt>false</tt> are used. However, they are integrated well enough into the language there should be no problem with that as long as you don't expect false and true to mean anything but literal false and true.
 
<syntaxhighlight lang="erlang">1> 1 < 2.
true
2> 1 < 1.
Line 1,077 ⟶ 1,025:
3> 0 == false.
false</syntaxhighlight>
 
=={{header|Excel}}==
The Logical category of functions includes the constants TRUE() and FALSE() which are displayed without the parantheses in cells. There are logical functions such as AND and OR too. For an AND truth table of two variables, take 3 cells, say A1,B1 and C1. In C1 type in :
 
<syntaxhighlight lang="excel">=AND(A1;B1)</syntaxhighlight>
 
Copy this until C4. Now as values are filled in from A1-A4 and B1-B4, C1-C4 gets updated.
 
<syntaxhighlight lang="text">0 0 FALSE
0 1 FALSE
1 0 FALSE
1 1 TRUE</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
The type bool is an abbreviation for the .NET framework type <code>System.Boolean</code>.
<syntaxhighlight lang="fsharp">type bool = System.Boolean</syntaxhighlight>
Instances of this type have values of either <code>true</code> or <code>false</code>.
 
=={{header|Factor}}==
In Factor any value except <code>f</code> is true, with <code>t</code> being the canonical true value.
 
=={{header|FALSE}}==
Zero is false and non-zero is true. This is used by the if and while operators ('''?''' and '''#'''). Comparators ('''=''' and '''<''') yield -1 for true and 0 for false.
 
=={{header|Fantom}}==
 
Conditional statements must return a <code>sys::Bool</code>, and the only two values are <code>true</code> and <code>false</code>.
 
=={{header|Forth}}==
In conditionals, zero is false, non-zero is true. There are predefined constants for the canonical forms. For FORTH-83 or later, FALSE is zero and TRUE is -1 (all bits set). For earlier FORTH standards, FALSE is zero and TRUE is 1.
<syntaxhighlight lang="forth">TRUE . \ -1
FALSE . \ 0</syntaxhighlight>
 
=={{header|Fortran}}==
Fortran started off in 1957 with only floating-point and fixed-point variables, so any calculations in the style of Boolean arithmetic would be done with integer values such as zero and not-zero, using multiplication and addition for '''and''' and '''or'''.
Line 1,115 ⟶ 1,056:
Fortran 66 introduced a '''logical''' data type which can be set to either '''.true.''' or '''.false.''' or be generated via logical expressions such as <=, etc. Such variables cannot be used in normal arithmetic with operators such as +-*/ but only with logical operators such as .OR. and so on. If via the EQUIVALENCE statement their numerical values (or, bit patterns) are inspected as say an integer, the values may well not be as anticipated and differ between computers and compilers. For instance, on the Burroughs 6700 an '''integer''' variable equivalenced to a '''logical''' variable would appear as '''.true.''' if odd, '''.false.''' if even.
 
The default storage size of a LOGICAL variable is the same as the default storage size of an INTEGER variable, which for many systems is 32 bits. This is done to simplify calculations of record sizes, or the alignment of variables in COMMON storage areas. It is usually possible to declare variables with certain byte sizes (normally only powers of two) so that LOGICAL*1 or similar declarations may be available. If used however there may arise alignment issues with adjacent variables of other types (such as REAL) that may require padding to even word boundaries for best access. Consider <syntaxhighlight lang=Fortran"fortran"> TYPE MIXED
LOGICAL*1 LIVE
REAL*8 VALUE
END TYPE MIXED
TYPE(MIXED) STUFF(100)</syntaxhighlight>
The array STUFF might occupy 900 bytes, or, 1600 bytes if each double-precision value has to be aligned to an eight-byte boundary. In the latter case, it may be better to declare LIVE and VALUE to be separate hundred-element arrays as in <syntaxhighlight lang=Fortran"fortran"> TYPE MIXED
LOGICAL*1 LIVE(100)
REAL*8 VALUE(100)
Line 1,126 ⟶ 1,067:
TYPE(MIXED) STUFF</syntaxhighlight>
Except that now only hundred-element variables of type MIXED can be declared. Either way, the record size needed for a disc file holding such items will need careful thought.
 
=={{header|Free Pascal}}==
In addition to the types defined by [[#Object Pascal|Object Pascal]], free Pascal defines the <code>qWordBool</code>, that has a <code>sizeOf</code> eight.<br>
Furthermore, True and False are not keywords from FPC v3.0.0. It is possible to assign any value to true and false, like strings but even objects.<br>
<syntaxhighlight lang="pascal">{$mode objfpc}{$ifdef mswindows}{$apptype console}{$endif}
const
true = 'true';
Line 1,156 ⟶ 1,096:
</syntaxhighlight>
JPD 2022/08/02
 
=={{header|Frink}}==
The literal boolean values are called <CODE>true</CODE> and <CODE>false</CODE>. In addition, in conditional expressions, the following are treated as true:
Line 1,167 ⟶ 1,106:
* The empty string
* The special value <CODE>undef</CODE>
 
=={{header|Futhark}}==
 
Futhark has a <code>bool</code> type, with the two values <code>True</code> and <code>False</code>. They are used for branching.
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=65324112fde86d51937b9cfcca0c51f9 Click this link to run this code]'''
<syntaxhighlight lang="gambas">Public Sub Main()
Dim bX As Boolean
 
Line 1,187 ⟶ 1,124:
True
</pre>
 
=={{header|GAP}}==
<syntaxhighlight lang="gap">1 < 2;
# true
 
Line 1,202 ⟶ 1,138:
fail = fail;
# true</syntaxhighlight>
 
=={{header|Go}}==
Go defines a built-in data type <code>bool</code>, which has exactly two values, represented by the keywords <code>true</code> and <code>false</code>. There is no conversion between booleans and other data types. Conditionals require a boolean value, so if i is a numeric type, for example, you must spell out <tt>if i != 0 {</tt> if you wish to interpret it as boolean.
Line 1,208 ⟶ 1,143:
The template package however, uses a different rule for <tt>if</tt> actions. There, it is testing if a "pipeline" is "empty" where the empty values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero.
 
<syntaxhighlight lang="go">
package main
 
Line 1,235 ⟶ 1,170:
fmt.Println("After :", reflect.TypeOf(bolStr)) // prt After : bool
}</syntaxhighlight>
 
=={{header|Groovy}}==
[[Groovy]] has a boolean "primitive" type and a Boolean "object wrapper" type directly derived from [[Java]]. See the Java solution to this task for more details.
 
Unlike Java, any null reference converts to a boolean "false", while any non-null object reference converts to a boolean "true"... EXCEPT if that object has a specific defined conversion to boolean "false". For example, for any numeric type, any zero value representation converts to "false" and any non-zero value converts to "true". For any collection type, non-empty converts to "true" and empty converts to "false".
 
=={{header|Haskell}}==
 
The Haskell standard [http://haskell.org/haskellwiki/Prelude Prelude] defines a data type <code>Bool</code>, which has exactly two members:
 
<syntaxhighlight lang="haskell">data Bool = False | True deriving (Eq, Ord, Enum, Read, Show, Bounded)</syntaxhighlight>
 
In addition to all the functionality of any other Haskell algebraic data type (e.g. [[pattern matching]]), and the specified derived typeclass instances (e.g. <code>False == False</code>, <code>succ False == True</code>, <code>(maxBound :: Bool) == True</code>, etc.), the built-in guard (“<code>|</code>”) and <code>if</code> syntaxes use Bool.
 
As with any other Haskell data type, there are no automatic conversions of other types to Bool.
 
=={{header|HicEst}}==
Zero is false, non-zero is true. Numbers also work in place of boolean expressions following this rule.
 
=={{header|HolyC}}==
In HolyC, there are the reserved keywords `TRUE` and `FALSE`. Variables to hold these values are declared as `Bool`.
Line 1,262 ⟶ 1,193:
* Any floating point type, where again, 0 gives false and everything else gives true.
* Any pointer type, where the null pointer gives false and any other pointer gives true.
 
=={{header|i}}==
Any non-zero number is true in 'i'.
<syntaxhighlight lang="i">main
//Bits aka Booleans.
b $= bit()
Line 1,286 ⟶ 1,216:
print(b)
}</syntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon do not use Boolean values for flow control. Rather they use success (returning a result, any result even a null) or failure (a signal) for this purpose. Built-in controls support not, and (&), and or (|). For an example of how this works, see [[Short-circuit_evaluation#Icon_and_Unicon|Short Circuit Evaluation]]. Icon and Unicon do support bit operations on integers which could be used to record Boolean state. See also [[Logical_operations#Icon_and_Unicon|Logical Operations]] for an example of how and when Boolean values might be implemented.
 
=={{header|Idris}}==
<syntaxhighlight lang="idris">Idris> :doc Bool
Data type Prelude.Bool.Bool : Type
Boolean Data Type
Line 1,301 ⟶ 1,229:
True : Bool
</syntaxhighlight>
 
=={{header|Inform 6}}==
Inform 6 has the constants <code>true</code> and <code>false</code>, which are identical to <code>1</code> and <code>0</code> respectively. One of these values will always be yielded by a condition operator (an operator that yields a boolean value). In addition, any non-zero value is considered to be true.
 
=={{header|Inform 7}}==
The Boolean type is called "truth state" and has the values "true" and "false".
 
However, Inform 7 distinguishes between Boolean values and conditions. Comparison expressions do not return truth states, and truth state expressions cannot be used directly in conditional statements. There is a conversion from condition to truth state:
<syntaxhighlight lang="inform7">let B be whether or not 123 is greater than 100;</syntaxhighlight>
And truth states can be used in conditions by adding an explicit comparison:
<syntaxhighlight lang="inform7">if B is true, say "123 is greater than 100."</syntaxhighlight>
 
Phrases (functions) cannot be defined to return a truth state directly. Instead, they are defined using "to decide whether" (or "to decide if") and can then be used as conditions:
<syntaxhighlight lang="inform7">To decide whether the CPU is working correctly:
if 123 is greater than 100, decide yes;
otherwise decide no.
Line 1,323 ⟶ 1,249:
[...or use as a condition]
if the CPU is working correctly, say "Whew."</syntaxhighlight>
 
=={{header|J}}==
 
Line 1,329 ⟶ 1,254:
 
This approach also works well with [[wp:Bayes'_theorem|Bayes' theorem]], as false matches 0% probability and true matches 100% probability.
 
=={{header|Java}}==
Java has <tt>true</tt> and <tt>false</tt> keywords, representing the only values of type <tt>boolean</tt>. There are also object wrappers <tt>Boolean.TRUE</tt> and <tt>Boolean.FALSE</tt>, of type <tt>Boolean</tt> which may be un-boxed into <tt>boolean</tt>s (auto-unboxed in Java 1.5+). There are no automatic conversions from any other types into <tt>boolean</tt>, and it is a compile-time error to use any type other than <tt>boolean</tt> or <tt>Boolean</tt> in a place that expects a <tt>boolean</tt> (e.g. if-statement condition, while-statement condition, operand of a logical operator, etc.).
 
=={{header|JavaScript}}==
The Boolean type has two values: <code>true</code> and <code>false</code>
Line 1,344 ⟶ 1,267:
 
(source: [http://www.ecma-international.org/publications/standards/Ecma-262.htm ECMAScript Language Reference])
 
=={{header|jq}}==
<tt>true</tt> and <tt>false</tt> are the only entities of type "boolean":
Line 1,359 ⟶ 1,281:
jq's logical operators, however, do not require boolean inputs. In brief, <tt>false</tt> and <tt>null</tt> are both regarded as false, and all other JSON entities are regarded as <tt>true</tt>. That is, all values except for <tt>false</tt> and <tt>null</tt> are truthy.
 
=={{header|Julia}}==
Julia has a built-in <code>Bool</code> type with values <code>true</code> and <code>false</code>.
 
Other objects do not represent boolean values and cannot be used in conditional expressions, for example:
<syntaxhighlight lang="julia">julia> if 1
println("true")
end
ERROR: type: non-boolean (Int64) used in boolean context</syntaxhighlight>
However, integers can be converted to boolean types with the <code>bool()</code> function (which treats nonzero values as <code>true</code>)
<syntaxhighlight lang="julia">julia> bool(-2:2)
5-element Bool Array:
true
Line 1,376 ⟶ 1,297:
true
true</syntaxhighlight>
 
=={{header|KonsolScript}}==
The Boolean type has two values: <code>true</code> and <code>false</code>
Line 1,384 ⟶ 1,304:
* String: the empty (zero-length) string is <code>false</code>; otherwise <code>true</code>
`
 
=={{header|Kotlin}}==
Booleans in Kotlin are given by the literals true and false, case sensitive, which are the only instances of the class Boolean.
 
=={{header|LabVIEW}}==
{{VI solution|LabVIEW_Boolean_values.png}}
 
=={{header|Lambdatalk}}==
Predefined constants are true and false:
<syntaxhighlight lang="scheme">
{if true then YES else NO}
-> YES
Line 1,400 ⟶ 1,317:
</syntaxhighlight>
Following the lambda calculus user defined booleans can be built
<syntaxhighlight lang="scheme">
{def TRUE {lambda {:a :b} :a}}
-> TRUE
Line 1,414 ⟶ 1,331:
 
</syntaxhighlight>
 
=={{header|Lasso}}==
Comparisons are evaluated in Lasso as either true of false, so "1 == 2" will evaluate as true, and "1 == 1" will evaluate as true.
Line 1,420 ⟶ 1,336:
A variable can also be assigned a boolean type, and as such then holds either true of false states.
 
<syntaxhighlight lang=Lasso"lasso ">!true
// => false
 
Line 1,435 ⟶ 1,351:
If the conditional results in an integer greater than zero, it is evaluated as boolean true.
 
<syntaxhighlight lang=Lasso"lasso ">local(x = string)
// size is 0
#x->size ? 'yes' | 'no'
Line 1,446 ⟶ 1,362:
<pre>no
yes</pre>
 
=={{header|Latitude}}==
 
Line 1,452 ⟶ 1,367:
 
By convention, objects which are used to represent failure are considered falsy. For instance, the standard library <code>'unit-test</code> module provides the <code>FailedTest</code> object, which is returned when a unit test fails. This object (and its children) test falsy when used as a conditional.
 
=={{header|LFE}}==
<syntaxhighlight lang="lisp">
> 'true
true
Line 1,464 ⟶ 1,378:
true
</syntaxhighlight>
 
 
=={{header|Lingo}}==
Lingo has the constants TRUE and FALSE. In numerical context they have the values 1 and 0. In boolean context any nonzero integer evaluates to TRUE.
<syntaxhighlight lang="lingo">put TRUE
-- 1
put FALSE
Line 1,474 ⟶ 1,386:
if 23 then put "Hello"
-- "Hello"</syntaxhighlight>
 
=={{header|Little}}==
For conditionals, numeric variables (including poly variables
Line 1,486 ⟶ 1,397:
 
 
<syntaxhighlight lang=C"c">int a = 0;
int b = 1;
int c;
Line 1,498 ⟶ 1,409:
if (str1) {puts("fifth test str1 is true");} // This should print
if (str2) {puts("sixth test str2 is false");} // This should not print</syntaxhighlight>
 
=={{header|LiveCode}}==
true and the string "true" are both logical true, similarly for false and "false" being logical false.
 
=={{header|Logo}}==
Logo has predefined symbols for true and false (<code>"true</code> and <code>"false</code>), which are the values returned by predicates and required by logical operators and conditionals.
<syntaxhighlight lang="logo">print 1 < 0 ; false
print 1 > 0 ; true
if "true [print "yes] ; yes
Line 1,510 ⟶ 1,419:
Unlike other lispy languages, there are no other implicit conversions.
You must test explicitly for zero or empty collections.
<syntaxhighlight lang="logo">if equal? 0 ln 1 [print "zero]
if empty? [] [print "empty] ; empty list
if empty? "|| [print "empty] ; empty word</syntaxhighlight>
 
=={{header|Lua}}==
All values in Lua other than <code>false</code> or <code>nil</code> are considered <code>true</code>:
<syntaxhighlight lang="lua">if 0 then print "0" end -- This prints
if "" then print"empty string" end -- This prints
if {} then print"empty table" end -- This prints
Line 1,522 ⟶ 1,430:
if true then print"true" end
if false then print"false" end -- This does not print</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
True is -1 and False is 0 (double type), but any comparison return boolean. We can define boolean type variables.
Line 1,537 ⟶ 1,444:
 
 
<syntaxhighlight lang=M2000"m2000 Interpreterinterpreter">
Module CheckBoolean {
A=True
Line 1,569 ⟶ 1,476:
 
</syntaxhighlight>
 
=={{header|Maple}}==
The keywords "true" and "false" are the default boolean values.
Line 1,575 ⟶ 1,481:
Expressions under assumptions may be evaluated logically using the <code>is</code> command.
Types may be tested, resulting in boolean values, using the <code>type</code> command.
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
True and False are the default boolean values.
To make any expression a boolean use the Boole[] function.
 
=={{header|MATLAB}}==
The keywords "true" and "false" are the default boolean values.
Line 1,588 ⟶ 1,492:
Sample Usage: (islogical() is a function that returns a boolean "1" if the input is a boolean, "0" otherwise)
 
<syntaxhighlight lang=MATLAB"matlab">>> islogical(true)
 
ans =
Line 1,623 ⟶ 1,527:
 
0</syntaxhighlight>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">is(1 < 2);
/* true */
 
Line 1,636 ⟶ 1,539:
not false;
/* true */</syntaxhighlight>
 
=={{header|Metafont}}==
Metafont has the type <tt>boolean</tt>; a boolean variable can be <tt>true</tt> or <tt>false</tt>.
Using non boolean values (or expressions that do not evaluate to a boolean value) results in a recoverable error; by default, any non-boolean value is interpreted as false.
 
=={{header|min}}==
{{works with|min|0.19.3}}
Line 1,651 ⟶ 1,552:
*empty string: <code>false</code>
*boolean: no conversion performed
 
=={{header|MiniScript}}==
In MiniScript, numbers represent boolean values, with additional fuzzy logic for degrees of truth. Built-in constants `true` and `false` are simply aliases for 1 and 0, respectively.
 
<syntaxhighlight lang=MiniScript"miniscript">boolTrue = true
boolFalse = false
 
Line 1,671 ⟶ 1,571:
mostlyTrue AND kindaTrue: 0.32
mostlyTrue OR kindaTrue: 0.88</pre>
 
=={{header|Mirah}}==
<syntaxhighlight lang="mirah">import java.util.ArrayList
import java.util.HashMap
 
Line 1,703 ⟶ 1,602:
 
</syntaxhighlight>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE boo;
 
IMPORT InOut;
Line 1,722 ⟶ 1,620:
UNTIL done
END boo.</syntaxhighlight>
 
=={{header|Modula-3}}==
Similar to [[Ada]], Modula-3 has a built-in <tt>BOOLEAN</tt> type defined as
<syntaxhighlight lang="modula3">TYPE BOOLEAN = {FALSE, TRUE}</syntaxhighlight>
 
=={{header|Monte}}==
 
Much like [[E]], Monte has built-in objects <tt>true</tt> and <tt>false</tt>, and a boolean [http://wiki.erights.org/wiki/Guard guard].
 
<syntaxhighlight lang=Monte"monte">
def example(input :boolean):
if input:
Line 1,737 ⟶ 1,633:
return "Input was false."
</syntaxhighlight>
 
=={{header|MUMPS}}==
 
Line 1,757 ⟶ 1,652:
Newer implementations of the language may also support !! (exclusve or).
There is one unary boolean operator: ' (not).</p>
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">a = true
b = false
 
Line 1,769 ⟶ 1,663:
{{out}}
<pre>a is true</pre>
 
=={{header|Neko}}==
 
Line 1,777 ⟶ 1,670:
is false, 0 or null. $istrue returning true if value is not false, not 0 and not null.
 
<syntaxhighlight lang="neko">/* boolean values */
$print(true, "\n");
$print(false, "\n");
Line 1,815 ⟶ 1,708:
$istrue(0) tests false
$istrue(1) tests true</pre>
 
=={{header|Nemerle}}==
In Nemerle, boolean values are held in variables of type '''bool''', and can be either '''true''' or '''false'''. Comparison expressions evaluate to boolean values as well.
 
=={{header|NetRexx}}==
NetRexx inherits boolean functionality directly from the [[Java]] virtual machine with the exception that the <code>true</code> and <code>false</code> keywords are not defined to the language.
Defining <code>true</code> and <code>false</code> variables can lead to name collisions during compilation so a simple expedient is to define boolean functions <code>isTrue</code>
and <code>isFalse</code> to return the appropriate values.
<syntaxhighlight lang=NetRexx"netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
Line 1,854 ⟶ 1,745:
0 is false
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">if true: echo "yes"
if false: echo "no"
 
# Other objects never represent true or false:
if 2: echo "compile error"</syntaxhighlight>
 
=={{header|Oberon-2}}==
<syntaxhighlight lang="oberon2">
VAR
a,b,c: BOOLEAN;
Line 1,871 ⟶ 1,760:
c := 1 > 2;
</syntaxhighlight>
 
=={{header|Objeck}}==
Objeck has a <tt>Bool</tt> type that is set to either <tt>true</tt> or <tt>false</tt>. By default boolean types are initialized to <tt>false</tt>. The boolean type also allows methods to be invoked, which perform simple conversions or print given values.
 
=={{header|Object Pascal}}==
In addition to the <code>Boolean</code> type defined by standard [[#Pascal|Pascal]], object Pascal defines the types <code>byteBool</code>, <code>wordBool</code> and <code>longBool</code>, having a <code>sizeOf</code> one, two, or four bytes respectively.
Line 1,883 ⟶ 1,770:
 
''See also [[#Delphi|Delphi]] and [[#Free Pascal|Free Pascal]]''
 
=={{header|Objective-C}}==
Objective-C follows pretty much the same rules as C. In addition to C, Objective-C has a <code>BOOL</code> boolean type, with values <code>YES</code> for true and <code>NO</code> for false. Objective-C also adds several special types of pointers; for pointers to objects (values of type <code>id</code>), the <code>nil</code> pointer is false, everything else is true; for pointers to classes (values of type <code>Class</code>), the <code>Nil</code> pointer is false, everything else is true.
 
=={{header|OCaml}}==
 
OCaml defines a built-in data type <code>bool</code>, which has exactly two members, represented by the keywords <code>true</code> and <code>false</code>:
 
<syntaxhighlight lang="ocaml">type bool = false | true</syntaxhighlight>
 
In addition to all the functionality of any other OCaml algebraic data type (e.g. [[pattern matching]]), and the functionality of any other OCaml data type (e.g. comparisons <code>false = false</code>, <code>false < true</code>, etc.), <code>bool</code> is also used in the guards in pattern matching (“<code>when</code>”) and <code>if</code> and <code>while</code> syntaxes.
 
As with any other OCaml data type, there are no automatic conversions of other types to <code>bool</code>.
 
=={{header|Octave}}==
Octave uses <tt>true</tt> (1) and <tt>false</tt> (0). The class of a variable holding a boolean value is ''logical'', which however can be casted to a numeric class, so that <code>r = true; r * 2</code> gives 2 as result. Any non-zero value is interpreted as true, and 0 as false.
 
=={{header|Oforth}}==
Oforth uses <tt>true</tt> (1) and <tt>false</tt> (0)
 
Any non-zero value is interpreted as true, and 0 as false.
 
=={{header|Ol}}==
 
Line 1,912 ⟶ 1,794:
 
p.s. Empty lists - '() - in conditionals is True.
 
=={{header|ooRexx}}==
 
<tt>.true</tt> or <tt>1</tt> are true, <tt>.false</tt> or <tt>0</tt> are false
 
=={{header|Order}}==
Order supplies the keywords <code>8true</code> and <code>8false</code>. Other types are not supposed to automatically convert to any boolean value (in practice some may do so due to implementation quirks, but this is not reliable).
 
=={{header|Oz}}==
<tt>true</tt> and <tt>false</tt> are the only boolean values. No other values are automatically converted to bool.
 
=={{header|PARI/GP}}==
Generally, false is 0 and true is nonzero. Certain other values also behave as false, like the vector [0]. Built-in boolean functions use 0 and 1 (but note that some functions like <code>ispower</code> are not boolean!).
Line 1,933 ⟶ 1,811:
* A vector (t_VEC), column vector (t_COL), or matrix (t_MAT) is false if and only if all of its components are 0. Note that <code>[]</code> is thus false.
* t_QUAD, t_POLMOD, t_RFRAC
 
=={{header|Pascal}}==
Pascal defines the type <code>Boolean</code> as a “special” enumeration type with exactly two elements:
Line 1,943 ⟶ 1,820:
 
''See also [[#Delphi|Delphi]], [[#Free Pascal|Free Pascal]], and [[#Object Pascal|Object Pascal]]''
 
=={{header|Perl}}==
 
<syntaxhighlight lang="perl">my $x = 0.0;
my $true_or_false = $x ? 'true' : 'false'; # false</syntaxhighlight>
or
<syntaxhighlight lang="perl">my $x = 1; # true
 
my $true_or_false;
Line 1,965 ⟶ 1,841:
Boolean comparison of zero against itself gives a value of one, but Perl uses short circuit evaluations, so any true or false value may be returned from a boolean expression:
 
<syntaxhighlight lang="perl">print (7 && 2); # 2, rather than 1(true)
print (2 && 7); # 7, rather than 1(true)
print (7 xor 2); # empty string, rather than 0(false)
Line 1,979 ⟶ 1,855:
Perl has no builtin "true" or "false" keywords. This is a caveat, because true and false are bareword strings and evaluate to true:
 
<syntaxhighlight lang="perl"># This does not work
# true and false are not special so will be treated as bareword strings
if (true) { print "true is true\n" }; # This prints
Line 1,988 ⟶ 1,864:
 
As a special case, literal <tt>1</tt>s and <tt>0</tt>s will never cause a "Useless use of a constant in void context" warning. Another special case worth pointing out here is that the string <tt>'0 but true'</tt> won't provoke a warning if it's used as a number.
 
=={{header|Phix}}==
Zero is false, any other number is true. Attempting to use a string or sequence as a boolean is assumed to be a programming logic blunder and causes a fatal run-time error.
Line 2,000 ⟶ 1,875:
 
The following example illustrates, and also emphasies the subtlety of the issue (no difference whatsoever if c, d, e, f are defined as bool):
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">3</span> <span style="color: #008080;">do</span>
Line 2,020 ⟶ 1,895:
--</span>
<!--</syntaxhighlight>-->
 
=={{header|PHP}}==
The values in PHP that are false are: <tt>FALSE</tt>, <tt>NULL</tt>, the number <tt>0</tt> (as an integer <tt>0</tt>, float <tt>0.0</tt>, or string <tt>'0'</tt>, but '''not''' the string <tt>"0.0"</tt>), the empty string <tt>""</tt>, the empty array <tt>array()</tt>, and "SimpleXML objects created from empty tags"(?).
Line 2,026 ⟶ 1,900:
Everything else is true. The keyword <tt>TRUE</tt> exists.
[http://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting]
 
=={{header|Picat}}==
Picat has the built-in <code>true/0</code> for true (it always succeeds) and <code>false/0</code> (or <code>fail/0</code>) for false. <code>false/0</code> (/<code>fail/0</code>) can be used to generate other solutions through backtracking.
 
<syntaxhighlight lang=Picat"picat">go ?=>
member(N,1..5),
println(N),
Line 2,052 ⟶ 1,925:
 
no</pre>
 
 
=={{header|PicoLisp}}==
Like in all Lisps, the symbol 'NIL' denotes "false", any other value "true". PicoLisp also uses NIL as the empty list, so the empty list is false.
Line 2,060 ⟶ 1,931:
value is available in the given context. Note that 'NIL' and 'T' are written in
uppercase letters (PicoLisp is case-sensitive).
 
=={{header|Pike}}==
<syntaxhighlight lang="pike">
> 0;
(3) Result: 0
Line 2,077 ⟶ 1,947:
>
</syntaxhighlight>
 
=={{header|PL/I}}==
True is <code>'1'b</code> and false is <code>'0'b</code>.
<syntaxhighlight lang="pli">Declare x bit(1);
x='1'b; /* True */
x='0'b; /* False */</syntaxhighlight>
Using the macro facility one can define reasonable symbols for true and false
<syntaxhighlight lang="pli">*process source attributes xref macro or(!);
tf: proc options(main);
%Dcl true char; %true='''1''b';
Line 2,098 ⟶ 1,967:
<pre>That's true
false was recognized</pre>
 
=={{header|PL/M}}==
 
In PL/M, even numbers are falsy and odd numbers are truthy. That is to say, conditional expressions test only the low bit of the value.
 
<syntaxhighlight lang="pli">IF 0 THEN /* THIS WON'T RUN */;
IF 1 THEN /* THIS WILL */;
IF 2 THEN /* THIS WON'T */;
Line 2,110 ⟶ 1,978:
Canonically, false is represented by <code>0</code> (all bits clear), and true by <code>0FFH</code> (all bits set). These are the values that conditional operators (like <code>=</code>) return.
 
<syntaxhighlight lang="pli">DECLARE A BYTE;
A = 4 < 5;
/* A IS NOW 0FFH */</syntaxhighlight>
Line 2,116 ⟶ 1,984:
Boolean literals are not included by default, but it is not uncommon for programmers to define them by hand:
 
<syntaxhighlight lang="pli">DECLARE FALSE LITERALLY '0', TRUE LITERALLY '0FFH';</syntaxhighlight>
 
=={{header|Plain English}}==
Boolean values are called flags. The flag literals are <code>yes</code> and <code>no</code>. You can <code>set</code> and <code>clear</code> flags.
 
=={{header|Pony}}==
Boolean values are <code>true</code> and <code>false</code>. Conditions must have type Bool, i.e. they are always true or false.
 
=={{header|PostScript}}==
 
Predefined constants are:
<syntaxhighlight lang="postscript">true
false</syntaxhighlight>
 
=={{header|PowerShell}}==
Two automatic variables exist for this purpose:
<syntaxhighlight lang="powershell">$true
$false</syntaxhighlight>
However, nearly everything can be converted to a boolean value, as detailed in the following list:
Line 2,141 ⟶ 2,005:
* any array with more than one item evaluates to '''true'''
* a reference to any object evaluates to '''true''', <code>$null</code> evaluates to '''false'''
 
=={{header|Python}}==
Python has a boolean data type with the only two possible values denoted by <code>True</code> and <code>False</code>.
Line 2,154 ⟶ 2,017:
 
'''Some examples:'''
<syntaxhighlight lang="python">>>> True
True
>>> not True
Line 2,193 ⟶ 2,056:
>>> bool("False")
True</syntaxhighlight>
 
=={{header|Quackery}}==
{{trans|Forth}}
In conditionals, zero is false, non-zero is true. There are predefined words for the canonical forms, <code>false</code> returns zero and <code>true</code> returns 1.
 
=={{header|R}}==
Similarly to Octave, R uses <tt>TRUE</tt> and <tt>FALSE</tt>, kept in variable of class logical, which is silently casted to 1 (TRUE) or 0 (FALSE) if used as numeric value. The opposite is also true: the value 0 can be used as FALSE, and non-zero numbers as TRUE.
 
The values T and F are given the values TRUE and FALSE respectively (for compatibility with S-Plus), though these may be changed to other values by the user.
 
=={{header|Racket}}==
 
Racket has the standard Scheme Boolean values <tt>#t</tt> and <tt>#f</tt>, and will also accept <tt>#true</tt> and <tt>#false</tt>. This is a literal syntax, so it can be used anywhere including in quoted positions. There are also bindings for <tt>true</tt> and <tt>false</tt> (but of course when these are quoted, the result is plain symbols). Like other Scheme descendants, many conditional constructs treat any non-false value as "truthy." So, for instance,
 
<syntaxhighlight lang=Racket"racket">(cond ([(< 4 3) 'apple]
['bloggle 'pear]
[else 'nectarine])</syntaxhighlight>
 
... evaluates to <tt>'pear</tt>, because <tt>'bloggle</tt> is not false.
 
=={{header|Raku}}==
(formerly Perl 6)
Line 2,219 ⟶ 2,078:
Raku provides an enumeration <code>Bool</code> with two values, <code>True</code> and <code>False</code>. Values of enumerations can be used as ordinary values or as mixins:
 
<syntaxhighlight lang="raku" line>my Bool $crashed = False;
my $val = 0 but True;</syntaxhighlight>
 
For a discussion of Boolean context (how Raku decides whether something is True or False): https://docs.raku.org/language/contexts#index-entry-Boolean_context.
 
=={{header|Raven}}==
Raven considers 0 as <code>FALSE</code>, -1 as <code>TRUE</code>
<syntaxhighlight lang=Raven"raven">TRUE print
FALSE print
2 1 > print # TRUE (-1)
3 2 < print # FALSE (0)
42 FALSE != # TRUE (-1)</syntaxhighlight>
 
=={{header|REBOL}}==
REBOL uses values of type '''logic!''' to represent boolean values. A boolean value can be 'true' or 'false', which also happen to be understood as predefined constants. Other constants are also provided to improve program readability:
Line 2,249 ⟶ 2,106:
 
As the last true value implies, pretty much any other type will evaluate to true. This is important to remember if you're used to a language where the value "0" is considered to be false -- in REBOL, it's true.
 
=={{header|ReScript}}==
 
Line 2,255 ⟶ 2,111:
 
ReScript's true/false compiles into a JavaScript true/false.
 
=={{header|Retro}}==
Zero is false and non-zero is true. Comparison functions return '''-1''' for true and '''0''' for false.
 
=={{header|REXX}}==
The REXX language enforces the values for &nbsp; ''true'' &nbsp; and &nbsp; ''false'', &nbsp; only the two values are valid:
Line 2,277 ⟶ 2,131:
 
===simplistic===
<syntaxhighlight lang="rexx"> true = 1
false = 0</syntaxhighlight>
 
===spruced up===
Some programmers like to "spruce up" such a simple assignment:
<syntaxhighlight lang="rexx">true = (1=1)
false = (1=0)</syntaxhighlight>
 
===more exactitudeness===
<syntaxhighlight lang="rexx">true = (1==1)
false = (1==0)</syntaxhighlight>
 
===oblique===
<syntaxhighlight lang="rexx">true = (1==1)
false = \true</syntaxhighlight>
[The parentheses aren't necessary in all of the above versions.]
<br><br>Some REXX interpreters allow the &nbsp; ''NOT'' &nbsp; (<code>¬</code>) character for negation:
<syntaxhighlight lang="rexx">false = ¬true</syntaxhighlight>
 
===esoteric===
<syntaxhighlight lang="rexx">true = 1984 = 1984
false = 'war' = 'peace'
false = 'freedom' = 'slavery'
Line 2,303 ⟶ 2,157:
Of course, in Orwellian terms, the above &nbsp; '''false''' &nbsp; statements are &nbsp; '''true''', &nbsp; but REXX isn't an Eric Arthur Blair reader.
<br><br>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
x = True
y = False
Line 2,312 ⟶ 2,165:
see "not x : " + (not x) + nl
</syntaxhighlight>
 
=={{header|Ruby}}==
The only values in Ruby that are false are: <code>false</code> and <code>nil</code>. They have synonyms <code>FALSE</code> and <code>NIL</code>.
Line 2,320 ⟶ 2,172:
<code>false</code>, <code>nil</code> and <code>true</code> are singleton instances of classes <code>FalseClass</code>, <code>NilClass</code> and <code>TrueClass</code> respectively.
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html#UF]
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">
fn main() {
// Rust contains a single boolean type: `bool`, represented by the keywords `true` and `false`.
Line 2,344 ⟶ 2,195:
bar is false.
</pre>
 
=={{header|Sather}}==
The BOOL type can be <code>true</code> or <code>false</code>. Sather never implicitly does casting of a type in another, so numeric value or other types cannot be used (implicitly) as boolean value; nonetheless an explicit "cast" can be done:
 
<syntaxhighlight lang="sather">v:BOOL := true; -- ok
i:INT := 1;
v := 1; -- wrong
Line 2,357 ⟶ 2,207:
 
In this case, <code>0.bool</code> is false, and <code>n.bool</code> with n not equal to 0 is true.
 
=={{header|Scala}}==
Booleans in Scala are given by the literals <code>true</code> and <code>false</code>, case sensitive, which are the only instances of the class <code>Boolean</code>.
 
=={{header|Scheme}}==
The only value in Scheme that is false is <tt>#f</tt>.
 
Everything else (including the empty list, unlike Lisp) is true. The constant <tt>#t</tt> represents the canonical true value.
 
=={{header|Seed7}}==
Seed7 defines the type <tt>boolean</tt>. The only values of <tt>boolean</tt> are <tt>TRUE</tt> and <tt>FALSE</tt>. There are no automatic conversions from any other types into <tt>boolean</tt>, and it is a compile-time error to use any type other than <tt>boolean</tt> in a place that expects a <tt>boolean</tt> (e.g. if-statement condition, while-statement condition, operand of a logical operator, etc.).
 
=={{header|Self}}==
 
Self has two objects, ''true'' and ''false''.
 
=={{header|SenseTalk}}==
True, Yes, and On are true; False, No, Off and Empty (an empty string) are false.
<syntaxhighlight lang="sensetalk">repeat with each item of [True, False, Yes, No, On, Off, ""]
put it & " is " & (it is true)
end repeat
Line 2,389 ⟶ 2,234:
is False
</pre>
 
=={{header|Sidef}}==
Sidef defines the ''true'' and ''false'' boolean values, which are part of the ''Bool'' type.
<syntaxhighlight lang="ruby">var t = true;
var f = false;</syntaxhighlight>
 
In conditional expressions, anything that evaluates to zero or nothing is considered ''false'', including empty arrays and empty hashes.
<syntaxhighlight lang="ruby">if (0 || "0" || false || nil || "" || [] || :()) {
say "true"
} else {
Line 2,403 ⟶ 2,247:
{{out}}
<pre>false</pre>
 
=={{header|Simula}}==
Simula has <tt>true</tt> and <tt>false</tt> keywords, representing the only values of type <tt>boolean</tt>. There are no automatic conversions from any other types into <tt>boolean</tt>, and it is a compile-time error to use any type other than <tt>boolean</tt> in a place that expects a <tt>boolean</tt> (e.g. if-statement condition, while-statement condition, operand of a logical operator, etc.).
 
=={{header|Slate}}==
Use <tt>True</tt> or <tt>False</tt>.
 
=={{header|Smalltalk}}==
Use "true" and "false".
<br>Smalltalk uses the Boolean class, which has two subclasses (True and False). <tt>true</tt> and <tt>false</tt> are singleton instances of those classes. E.g. an expression like <tt>5 = 5</tt> returns <tt>true</tt>.
 
=={{header|SNUSP}}==
Zero is false and non-zero is true, as used by the sole skip-if-zero operator ('''?''').
<syntaxhighlight lang="snusp">$!/?\=false= + =true=#
\-/</syntaxhighlight>
 
=={{header|SPL}}==
In SPL zero is false, any other value is true.
 
=={{header|Standard ML}}==
 
Standard ML defines a top-level data type <code>bool</code>, which has exactly two members, <code>true</code> and <code>false</code>:
 
<syntaxhighlight lang="sml">datatype bool = false | true</syntaxhighlight>
 
In addition to all the functionality of any other Standard ML algebraic data type (e.g. [[pattern matching]], equality <code>false = false</code>), <code>bool</code> is also used in <code>if</code> and <code>while</code> syntaxes.
 
As with any other Standard ML data type, there are no automatic conversions of other types to bool.
 
=={{header|Stata}}==
Stata uses the values 0 for "false" and 1 for "true". In expressions involving boolean operators, any nonzero numeric value (including missing values) is considered true.
 
=={{header|Swift}}==
Swift defines a built-in data type <code>Bool</code>, which has two values, represented by the keywords <code>true</code> and <code>false</code>. There is no conversion between booleans and other data types. Conditionals require a type that conforms to the <code>BooleanType</code> protocol, which provides a conversion to <code>Bool</code> for that type; types that conform include <code>Bool</code> and some other types.
 
=={{header|Tcl}}==
;True values:
Line 2,445 ⟶ 2,280:
Any of these values may be abbreviated, and mixed-case spellings are also acceptable. [http://www.tcl.tk/man/tcl8.5/TclLib/GetInt.htm]
Any other value gives an error. In an interactive tclsh session:
<syntaxhighlight lang="tcl">% if {""} then {puts true} else {puts false}
expected boolean value but got ""</syntaxhighlight>
 
Test for the boolean value of a string can be stuff like
<syntaxhighlight lang="tcl">if {[string is false -strict $string]} ...</syntaxhighlight>
which will test for "no" or "NO" or "0" or "False" or ...
 
=={{header|Trith}}==
The boolean constants are ''true'' and ''false''. In a conditional context, the only false values are ''false'' and ''nil'' -- every other value is true.
 
 
 
=={{header|UNIX Shell}}==
 
Line 2,470 ⟶ 2,301:
In the following example, after running the test command, the then syntactical component runs the optional branch if an exitcode is of zero determined:
 
<syntaxhighlight lang="sh">if
echo 'Looking for file' # This is the evaluation block
test -e foobar.fil # The exit code from this statement determines whether the branch runs
Line 2,484 ⟶ 2,315:
{{works with|ksh}}
 
<syntaxhighlight lang=Bash"bash">true && echo "true" || echo "false"</syntaxhighlight>
 
=={{header|Ursa}}==
Ursa has the boolean data type which can be declared using the declare (or decl) function.
<syntaxhighlight lang="ursa">decl boolean bool</syntaxhighlight>
Boolean values can be set to either true or false, or the result of an expression.
<syntaxhighlight lang="ursa">set bool true
# same as
set bool (= 2 2)
</syntaxhighlight>
or
<syntaxhighlight lang="ursa">set bool false
# same as
set bool (not (= 2 2))
</syntaxhighlight>
 
=={{header|VBA}}==
VBA has a boolean type. As an integer False is 0 and anything else is True. However True converts to -1. Booleans are False by default.
<syntaxhighlight lang="vb">Dim a As Integer
Dim b As Boolean
Debug.Print b
Line 2,517 ⟶ 2,346:
True
-1</pre>
 
=={{header|VBScript}}==
VBScript has the boolean subdatatype and also the two constants <code>True</code> and <code>False</code>.
When converting an integer to a boolean, <code>0</code> is <code>False</code> and anything not equal to <code>0</code> is <code>True</code>.
<syntaxhighlight lang="vb">
a = True
b = False
Line 2,532 ⟶ 2,360:
True False True False
</pre>
 
=={{header|Vim Script}}==
A non-zero <code>Number</code> is true, 0 is false.
 
Since a <code>String</code> is converted automatically to a <code>Number</code> when necessary, the following will print "false" because "foo" is converted to 0:
<syntaxhighlight lang="vim">if "foo"
echo "true"
else
echo "false"
endif</syntaxhighlight>
 
=={{header|Vlang}}==
V has a ''bool'' type, with literal values for ''true'' and ''false''. Numeric values are not used in conditional statements. 0 is not treated as false, and non-zero does not mean true, in V.
 
<syntaxhighlight lang="go">// Boolean Value, in V
// Tectonics: v run boolean-value.v
module main
Line 2,569 ⟶ 2,395:
true
false</pre>
 
=={{header|WDTE}}==
 
WDTE has a built-in boolean type, the two values of which are exposed by the <code>std</code> package's <code>true</code> and <code>false</code> functions. In general, however, built-in conditional functionality, such as <code>switch</code> expressions, considers any value that is not <code>true</code> to be <code>false</code>.
 
<syntaxhighlight lang="wdte">let io => import 'io';
let ex => switch 'this is irrelevant for this example' {
false => 'This is, obviously, not returned.';
Line 2,583 ⟶ 2,408:
 
The above prints "This is returned."
 
=={{header|Wren}}==
Wren has a core class, Bool, which has two instances ''true'' and ''false'' which are also ''reserved words'' in the language.
 
This class has two methods: the operator ''!'' which returns the logical complement of its receiver and ''toString'' which returns its string representation.
<syntaxhighlight lang="ecmascript">var embed = true
System.printAll([embed, ", ", !embed, ", ", "Is Wren embeddable? " + embed.toString])</syntaxhighlight>
 
Line 2,595 ⟶ 2,419:
true, false, Is Wren embeddable? true
</pre>
 
=={{header|XLISP}}==
Boolean "false" may be represented by <tt>#F</tt>, <tt>#!FALSE</tt>, <tt>NIL</tt>, or the empty list; any other value is counted as true in conditional expressions, but it is also possible to represent the Boolean value "true" using your choice of the symbols <tt>#T</tt>, <tt>#!TRUE</tt>, and <tt>T</tt>. All these symbols are case-insensitive. Note that <tt>T</tt>, unlike the others, is a variable: it is bound by default to the constant <tt>#T</tt>, but you can (although you shouldn't) assign it any other value including "false" (by doing something like <tt>(setq t nil)</tt>). Boolean values are printed as <tt>#T</tt> and <tt>()</tt>.
 
=={{header|XPL0}}==
An integer value equal to 0 is false, and a value not equal to 0 is true.
Relational operations evaluate to 0 for false and -1 for true. The
command word 'true' equals -1, and 'false' equals 0.
 
=={{header|XSLT}}==
<syntaxhighlight lang="xml"><xsl:if test="true() or false()">
True and false are returned by built-in XPath functions.
</xsl:if>
Line 2,614 ⟶ 2,435:
Test an attribute for its presence (empty or not), or whether a node set is empty.
</xsl:if></syntaxhighlight>
 
=={{header|Z80 Assembly}}==
There are no official constants for True or False, however the common convention is to use 0 for false and nonzero for true. In reality, any mutually exclusive condition will work. True/False can be tested using a variety of instructions. The most common are <code>CP</code> and <code>BIT</code> but in certain cases it can be done faster using <code>AND</code> or even <code>RRCA</code>.
 
All of the following can be used to test if the rightmost bit of a byte is 1.
<syntaxhighlight lang=Z80"z80">BIT 0,A
jr nz,true
;;;;;;;;;;;;;;;;
Line 2,629 ⟶ 2,449:
 
Of these three methods, the last one is the fastest and takes the least amount of bytes to encode. However, it does destroy the variable, which may not be an option depending on what you need to do with that data later. <code>BIT</code> is slower than the rest but doesn't alter registers or memory, just the flags, which is sometimes exactly what you need.
 
 
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">a:=True;
b:=False;
True.dir();</syntaxhighlight>
Line 2,647 ⟶ 2,464:
name numObjects oID otype properties size type typeID vaultPath
</pre>
 
=={{header|zonnon}}==
<syntaxhighlight lang="zonnon">
 
var
10,333

edits