Boolean Expressions

The if-Statement

Examples

Boolean Expressions

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

The if Statement

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

Syntax

If instead of statements, statement blocks are used, then these statement blocks must be enclosed within begin..end's.

Examples

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.
A First Look A First Look at Pascal Basic Input/Output Identifiers & Types
Constants Standard Functions If..Then Statement Case Statement
Repetitions Procedures and Functions Enumerated /Subrange Types Sets
I/O, Text Files Arrays Records Recursion
Pointer How to Debug Previous Exam Questions Advanced
ASCII Code Table Homepage University Homepage Computer Engineering Dept.