What is boolean in Pascal?
A boolean in Pascal is used to represent the built-in boolean data type. boolean can store one of two values: true or false. The size of the boolean data type is 1 byte.
Declaration
The boolean data type can be declared as:
variableName: boolean = true;
OR:
variableName: boolean = false;
Examples
Example 1
Consider the code snippet below, which shows the use of the boolean data type:
Program fixedRepetetion;varfoo: boolean = true;beginfoo := false;if (foo = true) thenwriteln('Boolean is true')else if (foo = false) thenwriteln('Boolean is false');end.
Explanation
- Line 3: A boolean type variable
foois initialized withtrue. - Line 6:
foois assignedfalse. - Lines 7-10: Checks whether the value of
fooistrueorfalse.
Example 2
Another way to initialize a boolean is to initialize it with a comparison expression. If the result of the comparison is true, boolean is initialized with true. If the result of the comparison is false, boolean is initialized with false.
Program fixedRepetetion;varfoo: boolean = (5<10);foo2: boolean = ('a'='b');beginwriteln('foo: ', foo);writeln('foo2: ', foo2);end.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved