If statements are used to make decisions.
The If Statement Expression Signs
< Less Than
<= Less Than or Equal To
> Greater Than
>= Greater Than or Equal To
= Equal To
<> Not Equal To
The Syntax for the If Statement
if
begin
do something;
end;
If Statement Example
if 5 > 2 then
begin
writeln(‘5 Is Greater Than 2’);
end;
The Output
5 Is Greater Than 2
Another If Statemet
if 5 < 2 then
begin
writeln(‘5 Is Less Than 2’);
end;
There will not be any output because 5 is not less than 2.
If statements can have multiple conditions. This is referred to as if - else statements.
Syntax for the If - Else Statement
If <condition>
begin
do something;
end
else if <condition>
begin
do something;
end
else
begin
do something;
end;
Code Download