A boolean either is a logical true or a logical false, where these 'true' and 'false' are also reserved words. Boolean expressions offer answers for questions. A boolean expression can either be constructed using the reserved words 'true' or 'false', using relational operators like '<', '>', '<=', '>=', '=', '<>', or using logical operations by 'and', 'not' or 'or'.
Examples for it:
if true then writeln('hello');
if (i<10) then writeln('i is less than 10'), where i is an integer or real variable with an initial value;
if ((i<10) and (i>5)) then writeln('i is between 5 and 10');
The relational operators are
As you have seen in the examples above, the if clause is used just like it is used in real life. If anything happens then do this else do anything else. eg. If I'm hungry then I eat else I do not eat.
The Syntax
If instead of statements, statement blocks are used, then these statement blocks must be enclosed within begin..end's.
program tryoutif(input,output); |
var |
i:integer; |
begin |
read(i); |
if (i<10) then |
writeln('i is less than 10') |
else writeln('i is greater than or equal to 10'); |
end. |