Difference between revisions of "Boolean"
m (typo) |
(show assignment to boolean variable) |
||
Line 4: | Line 4: | ||
'''Boolean''' is a logical datatype. Data of type boolean has one of only two values, either [[True|true]] or [[False|false]]. A Boolean variable is 1 byte in size. | '''Boolean''' is a logical datatype. Data of type boolean has one of only two values, either [[True|true]] or [[False|false]]. A Boolean variable is 1 byte in size. | ||
− | The '''true''' value | + | The '''true''' value can be assigned directly to a boolean variable or from the result of a comparison or test that was successful ("true"). Similarly the '''false''' value can be assigned directly or from the result of a comparison or test that was not successful ("false"). The Write() and Writeln() procedures will print a string that corresponds to the value of a Boolean variable (either "TRUE" or "FALSE"). A Boolean variable can be used as the expression in an if statement. |
<syntaxhighlight> | <syntaxhighlight> | ||
− | + | var | |
+ | tooLarge : Boolean = false; | ||
+ | boolString : ShortString; | ||
+ | begin | ||
+ | Writeln(tooLarge); | ||
+ | tooLarge := (0 = 0); | ||
+ | Writeln(tooLarge); | ||
+ | tooLarge := (3 > 5); | ||
+ | Writeln(tooLarge); | ||
+ | tooLarge := true; | ||
+ | Writeln(tooLarge); | ||
+ | if tooLarge then | ||
+ | Writeln('tooLarge is true') | ||
+ | else | ||
+ | Writeln('tooLarge is false'); | ||
+ | WriteStr(boolString,tooLarge); | ||
+ | Writeln(boolString); | ||
+ | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | '''FALSE''' | + | Ouputs:<br/> |
− | + | '''FALSE'''<br/> | |
− | < | + | '''TRUE'''<br/> |
− | + | '''FALSE'''<br/> | |
− | </ | + | '''TRUE'''<br/> |
− | '''TRUE''' | + | '''tooLarge is true'''<br/> |
+ | '''TRUE'''<br/> | ||
== See also == | == See also == |
Revision as of 09:06, 24 June 2016
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
中文(中国大陆) (zh_CN) │
Overview
Boolean is a logical datatype. Data of type boolean has one of only two values, either true or false. A Boolean variable is 1 byte in size.
The true value can be assigned directly to a boolean variable or from the result of a comparison or test that was successful ("true"). Similarly the false value can be assigned directly or from the result of a comparison or test that was not successful ("false"). The Write() and Writeln() procedures will print a string that corresponds to the value of a Boolean variable (either "TRUE" or "FALSE"). A Boolean variable can be used as the expression in an if statement.
var
tooLarge : Boolean = false;
boolString : ShortString;
begin
Writeln(tooLarge);
tooLarge := (0 = 0);
Writeln(tooLarge);
tooLarge := (3 > 5);
Writeln(tooLarge);
tooLarge := true;
Writeln(tooLarge);
if tooLarge then
Writeln('tooLarge is true')
else
Writeln('tooLarge is false');
WriteStr(boolString,tooLarge);
Writeln(boolString);
end
Ouputs:
FALSE
TRUE
FALSE
TRUE
tooLarge is true
TRUE
See also
simple data types |
|
---|---|
complex data types |