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.
The boolean
data type can be declared as:
variableName: boolean = true;
OR:
variableName: boolean = false;
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.
foo
is initialized with true
.foo
is assigned false
.foo
is true
or false
.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