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; var foo: boolean = true; begin foo := false; if (foo = true) then writeln('Boolean is true') else if (foo = false) then writeln('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; var foo: boolean = (5<10); foo2: boolean = ('a'='b'); begin writeln('foo: ', foo); writeln('foo2: ', foo2); end.
RELATED TAGS
CONTRIBUTOR
View all Courses