Boolean: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Boolean
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Overview | |
| 2 | + | ||
| 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 | + | ||
| 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 | + | ||
| 7 | + | ``` pascal | |
| 8 | + | program booleantest; | |
| 9 | + | var | |
| 10 | + | tooLarge : Boolean = false; | |
| 11 | + | boolString : ShortString; | |
| 12 | + | begin | |
| 13 | + | Writeln(tooLarge); | |
| 14 | + | tooLarge := (0 = 0); | |
| 15 | + | Writeln(tooLarge); | |
| 16 | + | tooLarge := (3 > 5); | |
| 17 | + | Writeln(tooLarge); | |
| 18 | + | tooLarge := true; | |
| 19 | + | Writeln(tooLarge); | |
| 20 | + | if tooLarge then | |
| 21 | + | Writeln('tooLarge is true') | |
| 22 | + | else | |
| 23 | + | Writeln('tooLarge is false'); | |
| 24 | + | WriteStr(boolString,tooLarge); | |
| 25 | + | Writeln(boolString); | |
| 26 | + | end. | |
| 27 | + | ``` | |
| 28 | + | ||
| 29 | + | Outputs:\ | |
| 30 | + | **FALSE** | |
| 31 | + | ||
| 32 | + | **`TRUE`**\ | |
| 33 | + | **`FALSE`**\ | |
| 34 | + | **`TRUE`**\ | |
| 35 | + | **`tooLarge is true`**\ | |
| 36 | + | **`TRUE`** | |
| 37 | + | ||
| 38 | + | ## See also | |
| 39 | + | ||
| 40 | + | - [[Boolean Expressions]] | |
| 41 | + | ||
| 42 | + | --- | |
| 43 | + | *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).* |
