Boolean: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | ## Overview | |
| 2 | 2 | ||
| 3 | 3 | The [[simple type]] **boolean** is a logical [[Data type|data type]]. Data of type boolean has one of only two values, either [[True|true]] or [[False|false]]. A boolean [[Variable|variable]] is 1 byte in size. | |
| 4 | 4 | ||
| 5 | 5 | 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() [[Procedure|procedures]] will print a [[String|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|if statement]]. The WriteStr() procedure can be used to store a string literal representing a boolean variable's value in a string variable. | |
| 6 | 6 | ||
| 7 | 7 | ``` pascal | |
| 8 | 8 | program booleantest; | |
| 9 | 9 | var | |
| 10 | 10 | tooLarge : Boolean = false; | |
| 11 | 11 | boolString : ShortString; | |
| 12 | 12 | begin | |
| 13 | 13 | Writeln(tooLarge); | |
| 14 | 14 | tooLarge := (0 = 0); | |
| 15 | 15 | Writeln(tooLarge); | |
| 16 | 16 | tooLarge := (3 > 5); | |
| 17 | 17 | Writeln(tooLarge); | |
| 18 | 18 | tooLarge := true; | |
| 19 | 19 | Writeln(tooLarge); | |
| 20 | 20 | if tooLarge then | |
| 21 | 21 | Writeln('tooLarge is true') | |
| 22 | 22 | else | |
| 23 | 23 | Writeln('tooLarge is false'); | |
| 24 | 24 | WriteStr(boolString,tooLarge); | |
| 25 | 25 | Writeln(boolString); | |
| 26 | 26 | end. | |
| 27 | 27 | ``` | |
| 28 | 28 | ||
| 29 | 29 | Outputs:\ | |
| 30 | 30 | ||
| 31 | - | ||
| 31 | + | ```text | |
| 32 | 32 | FALSE | |
| 33 | 33 | TRUE | |
| 34 | 34 | FALSE | |
| 35 | 35 | TRUE | |
| 36 | 36 | tooLarge is true | |
| 37 | 37 | TRUE | |
| 38 | 38 | ``` | |
| 39 | 39 | ||
| 40 | 40 | ## See also | |
| 41 | 41 | ||
| 42 | 42 | - [[Boolean Expressions]] | |
| 43 | 43 | ||
| 44 | 44 | --- | |
| 45 | 45 | *From the Free Pascal wiki, page "Boolean", as it stood on 2020-10-14 after a change by Rfc1394, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
