Boolean values: Difference between revisions
Content added Content deleted
imported>J7M (add example for SmallBASIC) |
imported>KayproKid (Added S-BASIC example) |
||
Line 2,426: | Line 2,426: | ||
v := 1.bool; -- ok |
v := 1.bool; -- ok |
||
if i.bool then ... end; -- ok</syntaxhighlight> |
if i.bool then ... end; -- ok</syntaxhighlight> |
||
=={{header|S-BASIC}}== |
|||
Although S-BASIC has no explicit boolean data type, it fully |
|||
supports boolean operations and allows strings, characters, and |
|||
integers to be used as though they were boolean variables. |
|||
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"> |
|||
$constant true = 0FFFFH |
|||
$constant false = 0 |
|||
var another = char |
|||
var adult, age = integer |
|||
another = 'Y' |
|||
adult = false |
|||
repeat |
|||
begin |
|||
input "Enter your age in years", age |
|||
adult = (age >= 18) |
|||
if adult then |
|||
print "You have full access" |
|||
else |
|||
print "You have restricted access" |
|||
input "Do another (y/n)", another |
|||
end |
|||
until not another |
|||
end |
|||
</systaxhighlight> |
|||
����� |
|||
In this case, <code>0.bool</code> is false, and <code>n.bool</code> with n not equal to 0 is true. |
In this case, <code>0.bool</code> is false, and <code>n.bool</code> with n not equal to 0 is true. |