Boolean values: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 28: Line 28:
=={{header|8th}}==
=={{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')
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}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 82: Line 83:
.include "../includeARM64.inc"
.include "../includeARM64.inc"
</lang>
</lang>

=={{header|ACL2}}==
=={{header|ACL2}}==
Same as [[Common Lisp|Boolean Values#Common Lisp]].
Same as [[Common Lisp|Boolean Values#Common Lisp]].
Line 343: Line 345:
110 END</lang>
110 END</lang>


==={{Header|BaCon}}===
==={{header|BaCon}}===
<lang qbasic>' Boolean TRUE and FALSE are non-zero and zero constants
<lang qbasic>' Boolean TRUE and FALSE are non-zero and zero constants
a = TRUE
a = TRUE
Line 376: Line 378:
print true
print true
</lang>
</lang>



=={{header|Batch File}}==
=={{header|Batch File}}==
Line 441: Line 442:
* 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, 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
* 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 shortand 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).

Unlike C/C++, there is no conversion in C# between other types and <code>Boolean</code>.


=={{header|C++}}==
=={{header|C++}}==
Line 449: Line 455:
* any pointer type, where the null pointer gives false and any other pointer gives true
* 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>
* 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|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 shortand 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).

Unlike C/C++, there is no conversion in C# between other types and <code>Boolean</code>.


=={{header|Clean}}==
=={{header|Clean}}==
Line 580: Line 581:
]
]
</lang>
</lang>



=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 615: Line 615:
=={{header|Delphi}}==
=={{header|Delphi}}==
In addition to the types defined by [[#Object Pascal|Object Pascal]], Delphi defines the type <code>Bool</code>.
In addition to the types defined by [[#Object Pascal|Object Pascal]], Delphi defines the type <code>Bool</code>.

=={{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|DWScript}}==
=={{header|DWScript}}==
Line 631: Line 627:
#f // <boolean> false</lang>
#f // <boolean> false</lang>
For the purpose of conditional statements, all objects other than <tt>#f</tt> evaluate to true.
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}}==
=={{header|E}}==
Line 663: Line 663:
(not 0) → #f
(not 0) → #f
</lang>
</lang>




=={{header|EGL}}==
=={{header|EGL}}==
Line 706: Line 704:
myInt: true
myInt: true
</pre>
</pre>



=={{header|Elena}}==
=={{header|Elena}}==
Line 841: Line 838:
TYPE(MIXED) STUFF</lang>
TYPE(MIXED) STUFF</lang>
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.
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.


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
Line 877: Line 877:
-1
-1
</pre>
</pre>

=={{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.


=={{header|Futhark}}==
=={{header|Futhark}}==
Line 1,097: Line 1,094:
* String: the empty (zero-length) string is <code>false</code>; otherwise <code>true</code>
* String: the empty (zero-length) string is <code>false</code>; otherwise <code>true</code>
`
`

=={{header|Kotlin}}==
=={{header|Kotlin}}==
Booleans in Kotlin are given by the literals true and false, case sensitive, which are the only instances of the class Boolean.
Booleans in Kotlin are given by the literals true and false, case sensitive, which are the only instances of the class Boolean.
Line 1,269: Line 1,267:
=={{header|Mathematica}}==
=={{header|Mathematica}}==
True and False are the default boolean values.
True and False are the default boolean values.
To make any expression a boolean use the Boole[] function.
To make any expression a boolean use the Boole[] function.

=={{header|MATLAB}}==
=={{header|MATLAB}}==
The keywords "true" and "false" are the default boolean values.
The keywords "true" and "false" are the default boolean values.
Line 1,331: Line 1,329:
Metafont has the type <tt>boolean</tt>; a boolean variable can be <tt>true</tt> or <tt>false</tt>.
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.
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|Microsoft Small Basic}}==
Microsoft Small Basic has two constants: <code>"True"</code> and <code>"False"</code>.<br>
<lang smallbasic>If c Then
notc = "False"
Else
notc = "True"
EndIf</lang>


=={{header|min}}==
=={{header|min}}==
Line 1,506: Line 1,512:
$istrue(0) tests false
$istrue(0) tests false
$istrue(1) tests true</pre>
$istrue(1) tests true</pre>



=={{header|Nemerle}}==
=={{header|Nemerle}}==
Line 1,546: Line 1,551:
0 is false
0 is false
</pre>
</pre>

=={{header|Microsoft Small Basic}}==
Microsoft Small Basic has two constants: <code>"True"</code> and <code>"False"</code>.<br>
<lang smallbasic>If c Then
notc = "False"
Else
notc = "True"
EndIf</lang>


=={{header|Nim}}==
=={{header|Nim}}==
Line 1,574: Line 1,571:
=={{header|Objeck}}==
=={{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.
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|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|Object Pascal}}==
=={{header|Object Pascal}}==
Line 1,586: Line 1,580:


''See also [[#Delphi|Delphi]] and [[#Free Pascal|Free Pascal]]''
''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}}==
=={{header|OCaml}}==
Line 1,688: Line 1,685:


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.
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|Perl 6}}==
{{works with|Rakudo|2015.12}}

Perl 6 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:

<lang perl6>my Bool $crashed = False;
my $val = 0 but True;</lang>

For a discussion of Boolean context (i.e. how Perl decides whether something is true or false), see [http://perlcabal.org/syn/S02.html#Context Synopsis 2].


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,759: Line 1,746:
=={{header|Pony}}==
=={{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.
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:
<lang postscript>true
false</lang>


=={{header|PowerBASIC}}==
=={{header|PowerBASIC}}==
Line 1,769: Line 1,762:
x = ISFALSE(1 = 1) ' returns 0
x = ISFALSE(1 = 1) ' returns 0
x = ISFALSE(1 = 0) ' returns -1</lang>
x = ISFALSE(1 = 0) ' returns -1</lang>

=={{header|PostScript}}==

Predefined constants are:
<lang postscript>true
false</lang>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
Line 1,857: Line 1,844:


... evaluates to <tt>'pear</tt>, because <tt>'bloggle</tt> is not false.
... evaluates to <tt>'pear</tt>, because <tt>'bloggle</tt> is not false.

=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2015.12}}

Perl 6 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:

<lang perl6>my Bool $crashed = False;
my $val = 0 but True;</lang>

For a discussion of Boolean context (i.e. how Perl decides whether something is true or false), see [http://perlcabal.org/syn/S02.html#Context Synopsis 2].


=={{header|Raven}}==
=={{header|Raven}}==
Line 1,989: Line 1,987:
=={{header|Self}}==
=={{header|Self}}==


Self has two objects, ''true'' and ''false''.
Self has two objects, ''true'' and ''false''.

=={{header|SenseTalk}}==
=={{header|SenseTalk}}==
True, Yes, and On are true; False, No, Off and Empty (an empty string) are false.
True, Yes, and On are true; False, No, Off and Empty (an empty string) are false.
Line 2,157: Line 2,156:
True False True False
True False True False
</pre>
</pre>

=={{header|Visual Basic}}==

VB has the <code>Boolean</code> data type and the constants <code>True</code> and <code>False</code>, in addition to what's listed under [[#BASIC|BASIC]], above. When used outside of a boolean context, <code>True</code> and <code>False</code> return values depending on their context -- <code>-1</code> and <code>0</code> in a numeric context, <code>"True"</code> and <code>"False"</code> if used as strings.
<br>When converting an integer to a boolean, <code>0</code> is <code>False</code> and anything not equal to <code>0</code> is

<lang vb>Dim x As Boolean
x = IIf(Int(Rnd * 2), True, False)
MsgBox x</lang>


=={{header|Vim Script}}==
=={{header|Vim Script}}==
Line 2,176: Line 2,166:
echo "false"
echo "false"
endif</lang>
endif</lang>

=={{header|Visual Basic}}==

VB has the <code>Boolean</code> data type and the constants <code>True</code> and <code>False</code>, in addition to what's listed under [[#BASIC|BASIC]], above. When used outside of a boolean context, <code>True</code> and <code>False</code> return values depending on their context -- <code>-1</code> and <code>0</code> in a numeric context, <code>"True"</code> and <code>"False"</code> if used as strings.
<br>When converting an integer to a boolean, <code>0</code> is <code>False</code> and anything not equal to <code>0</code> is

<lang vb>Dim x As Boolean
x = IIf(Int(Rnd * 2), True, False)
MsgBox x</lang>


=={{header|WDTE}}==
=={{header|WDTE}}==