Boolean values: Difference between revisions

Content added Content deleted
(shorten Pascal, by _grouping_ definitions into the norms that originally introduced certain types)
Line 105:
=={{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).
Line 541 ⟶ 542:
 
=={{header|Delphi}}==
In addition to the types defined by [[#Object Pascal|Object Pascal]], Delphi defines the type <code>Bool</code>.
 
Delphi (like Pascal) has standard ordinal <code>Boolean</code> type with two values: <code>True</code> and <code>False</code>, <code>Ord(False) = 0</code>, <code>Ord(True) = 1</code>
 
Delphi also defines <code>BOOL</code>, <code>ByteBool</code>, <code>WordBool</code> and <code>LongBool</code> types (to simplify C functions' import). For these types zero value is <code>False</code> and any nonzero value is <code>True</code>.
 
=={{header|Déjà Vu}}==
Line 551 ⟶ 549:
 
=={{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>.
 
Line 808 ⟶ 805:
-1
</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}}==
Line 1,227:
not false;
/* true */</lang>
 
=={{header|Metafont}}==
Metafont has the type <tt>boolean</tt>; a boolean variable can be <tt>true</tt> or <tt>false</tt>.
Line 1,444 ⟶ 1,445:
=={{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}}==
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.
They were introduced primarily to ease interfacing with code written in other languages, such as [[#C|C]].
These types only have <code>ord(false)</code> defined as zero, and ''any'' other ordinal value represents <code>true</code>.
 
Nonetheless, <code>Boolean</code> is ''the'' preferred type.
 
''See also [[#Delphi|Delphi]] and [[#Free Pascal|Free Pascal]]''
 
=={{header|OCaml}}==
Line 1,493 ⟶ 1,503:
 
=={{header|Pascal}}==
Pascal hasdefines standardthe type <code>Boolean</code> as a “special” enumeration type with exactly two valueselements: <code>True</code> and <code>False</code>.<br>
<code>false</code> and <code>true</code>.
In all flavors of pascal there is no such foolishness as numbers of empty strings or pointers ( initialized or otherwise ) being evaluated as boolean. There is the boolean type as defined by the RTL statements such as:
It is guaranteed that <code>ord(false)</code> is&nbsp;<code>0</code> and <code>ord(false)</code> is&nbsp;<code>1</code>.
<lang pascal>
var
pInt : ^integer ;
ValidP : boolean ;
</lang>
 
There is no automatic conversion from integer values to Boolean values, as it is prevalent in many other languages.
<lang pascal>
Instead, one has to write a Boolean expression, for example <code>myInteger &lt;&gt; 0</code> in order to get an assignment-compatible type.
if pInt then ...
</lang>
 
''See also [[#Delphi|Delphi]], [[#Free Pascal|Free Pascal]], and [[#Object Pascal|Object Pascal]]''
or
 
<lang pascal>
if pInt^ then ...
</lang>
 
Will always be a syntax error. The following correct evaluations of variables are allowed:
 
<lang pascal>
if not(pInt = nil) then ValidP := true ;
</lang>
 
or
 
<lang pascal>
if ( ValidP ) and (pInt^ <> 0) then ...
</lang>
 
=={{header|Perl}}==
Line 1,883 ⟶ 1,872:
{{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.).
Line 1,953 ⟶ 1,943:
 
0 OK, 0:52</pre>
 
=={{header|UNIX Shell}}==
 
Line 1,995 ⟶ 1,986:
set bool (not (= 2 2))
</lang>
 
=={{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.