Boolean values: Difference between revisions

Content added Content deleted
(Added Commodore BASIC - Regrouped other BASIC variants under BASIC.)
Line 199: Line 199:


<lang AppleScript>sortItems from L given reversal:yes</lang>
<lang AppleScript>sortItems from L given reversal:yes</lang>

=={{header|Applesoft BASIC}}==
IF statement condition treats any non-zero numeric value as true. Comparison operators evaluate to 1 (true) or 0 (false).
Examples:<lang ApplesoftBASIC>? 2 = 3
? 2 = 2
IF 7 THEN ?"HELLO"</lang>

{{out}}
<pre>0
1
HELLO</pre>


=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
Line 348: Line 337:
100 IF B%<>0 THEN PRINT "TEST SIX (TRUE BY COMPARISON) DOES PRINT"
100 IF B%<>0 THEN PRINT "TEST SIX (TRUE BY COMPARISON) DOES PRINT"
110 END</lang>
110 END</lang>

==={{header|Applesoft BASIC}}===
IF statement condition treats any non-zero numeric value as true. Comparison operators evaluate to 1 (true) or 0 (false).
Examples:<lang ApplesoftBASIC>? 2 = 3
? 2 = 2
IF 7 THEN ?"HELLO"</lang>

{{out}}
<pre>0
1
HELLO</pre>


==={{header|BaCon}}===
==={{header|BaCon}}===
Line 372: Line 372:
TRUE</pre>
TRUE</pre>


=={{header|BASIC256}}==
==={{header|BASIC256}}===
<lang basic256>
<lang basic256>
' BASIC256 used numbers to represent true and false
' BASIC256 used numbers to represent true and false
Line 382: Line 382:
print true
print true
</lang>
</lang>

==={{header|BBC BASIC}}===
<lang bbcbasic> REM BBC BASIC uses integers to represent Booleans; the keywords
REM FALSE and TRUE equate to 0 and -1 (&FFFFFFFF) respectively:
PRINT FALSE
PRINT TRUE</lang>

==={{header|Commodore BASIC}}===
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.

<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%
30 print "False is evaluated as:";f%
40 print:print "Any non-zero number will evaluate to"
50 print "true as shown in this example:":print
60 for i=-2 to 2
70 print i;" = ";
80 if i then print "True":goto 100
90 print "False"
100 next</lang>

{{out}}
<pre>
True is evaulated as:-1
False is evaluated as: 0
Any non-zero number will evaluate to
true as shown in this example:
-2 = True
-1 = True
0 = False
1 = True
2 = True
ready.
&#9608;
</pre>

==={{header|FreeBASIC}}===
FreeBASIC has a built-in Boolean type (equivalent to a signed one byte integer) with built-in constants true and false to represent values of that type. Note also that:

* Numeric expresions can be converted to the Boolean type either implicitly or using the CBool operator - zero is converted to false and non-zero to true.

* Boolean expressions can be converted to a numeric type either implicitly or using the appropriate cast operator (CInt, CByte, CDbl etc) - false is converted to 0 and true to -1.

* String expressions such as "false" and "true" (regardless of case) can also be converted to Boolean using CBool.

* It is possible to overload CBool for user-defined types to yield a Boolean value.


Sample code:
<lang freebasic>' FB 1.05.0 Win64

Dim i As Integer = 23
Dim s As String = "False"
Dim b As Boolean
b = i
Print b
b = CBool(s)
Print b
i = b
Print i
i = CInt(true)
Print i
Sleep</lang>

{{out}}
<pre>
true
false
0
-1
</pre>

==={{header|Liberty BASIC}}===
IF-statement, loop condition treats any non-zero integer as true.
Comparison operators evaluate to 1 (true) or 0 (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|PowerBASIC}}===

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]].)

<lang powerbasic>DIM x AS LONG
x = ISTRUE(1 = 1) ' returns -1
x = ISTRUE(1 = 0) ' returns 0
x = ISFALSE(1 = 1) ' returns 0
x = ISFALSE(1 = 0) ' returns -1</lang>

==={{header|PureBasic}}===
PureBasic does not have a Boolean variable type. An integer type is typically used instead. Boolean values are only supported as part of a loop's condition (While/Wend, Repeat/Until) or in a conditional (If/Endif). In these cases if the result of a variable or a numeric expression is zero it is evaluated as False, otherwise it is evaluated as True. A string variable assigned a null string would be evaluated as False.

==={{header|QBasic}}===
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:

<lang QBASIC>
CONST FALSE=0
CONST TRUE = Not FALSE
Print FALSE
Print TRUE
</Lang>

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:

<lang QBASIC>
10 DEF FNFALSE = 0
20 DEF FNTRUE = NOT FNFALSE
30 Print FNFALSE
40 Print NFTRUE
</Lang>

==={{header|Run BASIC}}===
Basically 0 is false and 1 is true
<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"
if 2 > 1 then print "2 > 1 TRUE"
if not(2 < 1) then print "2 not < 1"
if not(1 = 0) then print "1 not = 0"</lang>

==={{header|smart BASIC}}===
<ul>
<li>IF/THEN statements treat any non-zero value as true and zero as false.</li>
<li>Comparison operators DO NOT calculate in smart BASIC. For example, PRINT (1 > 4) WILL NOT evaluate to produce a zero value (0) indicating a false condition. It will produce an error. All Boolean evaluations in smart BASIC must be determined within IF/THEN statements. </li>
</ul>

==={{header|TI-89 BASIC}}===

There are boolean literals <code>true</code> and <code>false</code>. No other values may be used where a boolean is expected.

==={{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.
<lang>t = 1 = 1
f = 0 = 1

Print "False = ";f;", True = ";t</lang>
{{out}}
<pre>False = 0, True = 1

0 OK, 0:52</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|Batch File}}==
=={{header|Batch File}}==
Line 416: Line 575:
b is false
b is false
</pre>
</pre>

=={{header|BBC BASIC}}==
<lang bbcbasic> REM BBC BASIC uses integers to represent Booleans; the keywords
REM FALSE and TRUE equate to 0 and -1 (&FFFFFFFF) respectively:
PRINT FALSE
PRINT TRUE</lang>


=={{header|bc}}==
=={{header|bc}}==
Line 846: Line 998:
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.
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}}==
FreeBASIC has a built-in Boolean type (equivalent to a signed one byte integer) with built-in constants true and false to represent values of that type. Note also that:

* Numeric expresions can be converted to the Boolean type either implicitly or using the CBool operator - zero is converted to false and non-zero to true.

* Boolean expressions can be converted to a numeric type either implicitly or using the appropriate cast operator (CInt, CByte, CDbl etc) - false is converted to 0 and true to -1.

* String expressions such as "false" and "true" (regardless of case) can also be converted to Boolean using CBool.

* It is possible to overload CBool for user-defined types to yield a Boolean value.


Sample code:
<lang freebasic>' FB 1.05.0 Win64

Dim i As Integer = 23
Dim s As String = "False"
Dim b As Boolean
b = i
Print b
b = CBool(s)
Print b
i = b
Print i
i = CInt(true)
Print i
Sleep</lang>

{{out}}
<pre>
true
false
0
-1
</pre>


=={{header|Frink}}==
=={{header|Frink}}==
Line 1,190: Line 1,307:
</lang>
</lang>


=={{header|Liberty BASIC}}==
IF-statement, loop condition treats any non-zero integer as true.
Comparison operators evaluate to 1 (true) or 0 (false).


=={{header|Lingo}}==
=={{header|Lingo}}==
Line 1,368: Line 1,482:
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,794: Line 1,900:
<lang postscript>true
<lang postscript>true
false</lang>
false</lang>

=={{header|PowerBASIC}}==

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]].)

<lang powerbasic>DIM x AS LONG
x = ISTRUE(1 = 1) ' returns -1
x = ISTRUE(1 = 0) ' returns 0
x = ISFALSE(1 = 1) ' returns 0
x = ISFALSE(1 = 0) ' returns -1</lang>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
Line 1,816: Line 1,912:
* any array with more than one item evaluates to '''true'''
* any array with more than one item evaluates to '''true'''
* a reference to any object evaluates to '''true''', <code>$null</code> evaluates to '''false'''
* a reference to any object evaluates to '''true''', <code>$null</code> evaluates to '''false'''

=={{header|PureBasic}}==
PureBasic does not have a Boolean variable type. An integer type is typically used instead. Boolean values are only supported as part of a loop's condition (While/Wend, Repeat/Until) or in a conditional (If/Endif). In these cases if the result of a variable or a numeric expression is zero it is evaluated as False, otherwise it is evaluated as True. A string variable assigned a null string would be evaluated as False.


=={{header|Python}}==
=={{header|Python}}==
Line 1,871: Line 1,964:
>>> bool("False")
>>> bool("False")
True</lang>
True</lang>

=={{header|QBasic}}==
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:

<lang QBASIC>
CONST FALSE=0
CONST TRUE = Not FALSE
Print FALSE
Print TRUE
</Lang>

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:

<lang QBASIC>
10 DEF FNFALSE = 0
20 DEF FNTRUE = NOT FNFALSE
30 Print FNFALSE
40 Print NFTRUE
</Lang>


=={{header|R}}==
=={{header|R}}==
Line 2,007: Line 2,081:
<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.
<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]
[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html#UF]

=={{header|Run BASIC}}==
Basically 0 is false and 1 is true
<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"
if 2 > 1 then print "2 > 1 TRUE"
if not(2 < 1) then print "2 not < 1"
if not(1 = 0) then print "1 not = 0"</lang>


=={{header|Rust}}==
=={{header|Rust}}==
Line 2,079: Line 2,144:
=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
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>.
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|smart BASIC}}==
<ul>
<li>IF/THEN statements treat any non-zero value as true and zero as false.</li>
<li>Comparison operators DO NOT calculate in smart BASIC. For example, PRINT (1 > 4) WILL NOT evaluate to produce a zero value (0) indicating a false condition. It will produce an error. All Boolean evaluations in smart BASIC must be determined within IF/THEN statements. </li>
</ul>


=={{header|SNUSP}}==
=={{header|SNUSP}}==
Line 2,123: Line 2,182:
<lang tcl>if {[string is false -strict $string]} ...</lang>
<lang tcl>if {[string is false -strict $string]} ...</lang>
which will test for "no" or "NO" or "0" or "False" or ...
which will test for "no" or "NO" or "0" or "False" or ...

=={{header|TI-89 BASIC}}==

There are boolean literals <code>true</code> and <code>false</code>. No other values may be used where a boolean is expected.


=={{header|Trith}}==
=={{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.
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|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.
<lang>t = 1 = 1
f = 0 = 1


Print "False = ";f;", True = ";t</lang>
{{out}}
<pre>False = 0, True = 1

0 OK, 0:52</pre>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
Line 2,227: Line 2,273:
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}}==