beautypg.com

Rice Lake iRite IDE User Manual

Page 28

background image

24

920i

Programming Reference

The if-else is used when the program must decide which of exactly two different paths of execution must be
executed. The path that will execute the statement or statements in will be chosen if
evaluates to true. Here is an example:

if iAge => 18 then

sStatus := "Adult";

else

sStatus := "Minor";

end if;

If the statement is false, then the statement or statements in will be executed. Once the
expression is evaluated and one of the paths is chosen, the expression is not evaluated again. This means the
statement will terminate after one of the paths has been executed.

For example, if the expression was true and we were executing , and within the code in
we change some part of so it would at that moment evaluate to false,
would still not be executed. This point is more relevant in the next form called the if-elsif.

ELSIF

expr

stmt-list

THEN

Figure 3-14. Optional Else-If Statement Syntax

The if-elsif version is used when a multi-way decision is necessary and has this general form:

if then

elsif then

elsif then

elsif then

else

end if;

Here is an example of the if-elsif form:

if rWeight <= 2.0 then

iGrade := 1;

elsif (rWeight > 2.0) and (rWeight < 4.5) then

iGrade := 2;

elsif (rWeight > 4.5) and (rWeight < 9.25) then

iGrade := 3;

elsif (rWeight > 9.25) and (rWeight < 11.875) then

iGrade := 4;

else

iGrade := 0;

sErrorString := "Invalid Weight!";

end if;

This manual is related to the following products: