Boolean values: Difference between revisions

Content added Content deleted
imported>KayproKid
m (fixed run-over between languages)
imported>KayproKid
m (→‎{{header|S-BASIC}}: minor cleanup and display output)
Line 2,429: Line 2,429:


=={{header|S-BASIC}}==
=={{header|S-BASIC}}==
Although S-BASIC has no explicit boolean data type, it fully
Although S-BASIC has no explicit boolean data type, it allows integer,
real, fixed, string, and character variables to hold the results of boolean operations and to represent true and false conditions in IF, WHILE, and REPEAT statements. For types real.double, real, and fixed, a value of zero is false, and any non-zero value is true. For integers, the value 0 is treated as false, while -1 (or FFFFH), the bit-wise negation of zero, is treated as true.
supports boolean operations and allows strings, characters, and
For characters and strings, 'Y', 'y', 'T', and 't' are treated as true,
integers to be used as though they were boolean variables.
while 'N', 'n', 'F', and 'f' are treated as false. (For strings, only the first character is considered.) For convenience, the $CONSTANT compiler directive can be used to provide values for "true" and "false".
For integers, the value 0 is treated as "false", while -1
(FFFFH), the bit-wise negation of zero, is treated as "true".
For characters and strings, 'Y', 'y', 'T', and 't' are treated as
true, while 'N', 'n', 'F', and 'f' are treated as false. The
$CONSTANT compiler command can be used to provide a value for
"true" and "false". In the following example, the character
variable "another" and the integer variable "adult" both function
as boolean variables.
<syntaxhighlight lang = "BASIC">
<syntaxhighlight lang = "BASIC">
$constant true = 0FFFFH
$constant true = 0FFFFH
$constant false = 0
$constant false = 0


var another = char
var a, another = char
var adult, age = integer
var b, adult, age = integer
var c = real

another = 'Y'
adult = false


repeat
repeat
begin
begin
input "Enter your age in years", age
input "Applicant's age in years"; age
adult = (age >= 18)
adult = (age >= 18)
if adult then
if adult then
print "You have full access"
print "Applicant has full access"
else
else
print "You have restricted access"
print "Applicant has restricted access"
input "Do another (y/n)", another
input "Do another (y/n)"; another
end
end
until not another
until not another


a = (2 > 3)
b = (2 > 3)
c = (2 > 3)
print "2 > 3 as char: "; a
print "2 > 3 as int : "; b
print "not (2 > 3) : "; not b
print "2 > 3 as real: "; c
print "not (2 > 3) : "; not c
end
end
</systaxhighlight>
</syntaxhighlight>
{{out}}
<pre>
Applicant's age in years? 19
Applicant has full access
Do another (y/n)? n
2 > 3 as char: F
2 > 3 as int : 0
not (2 > 3) :-1
2 > 3 as real: 0
not (2 > 3) :-1
</pre>


=={{header|Scala}}==
=={{header|Scala}}==