The if instruction executes JADE instructions dependent upon a condition.
Syntax
The forms of the JADE conditional instruction are:
if boolean-expression then
[instructions]
endif;
This executes the instructions if the condition evaluates to true.
if boolean-expression then
[instructions]
else
[instructions]
endif;
This executes the first sequence of instructions if the condition evaluates to true and the second sequence if the condition evaluates to false.
if boolean-expression then
[instructions]
elseif boolean-expression then
[instructions]
elseif boolean-expression then
[instructions]
else
[instructions]
endif;
The elseif clause is equivalent to an else clause followed by a further nested if instruction. The else part remains optional when there is one or more elseif clause.
Description
Use the if instruction to perform conditional execution, based on the evaluation of an expression.
Examples
The following example shows a series of nested if instructions.
getJobTitle(level: Integer): String;
begin
if level = 1 then
return "CEO";
else
if level = 2 then
return "Project Manager";
else
if level = 3 then
return "Analyst";
else
if level = 4 then
return "Programmer";
else
return "Invalid level";
endif;
endif;
endif;
endif;
end;
This can be written in a more compact and readable way, by making use of the elseif clause, as shown in the following example.
getJobTitle(level: Integer): String;
begin
if level = 1 then
return "CEO";
elseif level = 2 then
return "Project Manager";
elseif level = 3 then
return "Analyst";
elseif level = 4 then
return "Programmer";
else
return "Invalid level";
endif;
end;