if J <> 0 then Result := I/J;
The syntax of an if...then...else statement is
if expression then statement1 else statement2
where expression returns a Boolean value. If expression is True, then statement1 is executed
otherwise statement2 is executed. For example,
if J = 0 then
Exit
else
Result := I/J;
The then and else clauses contain one statement each, but it can be a structured statement. For example,
if J <> 0 then
begin
Result := I/J;
Count := Count + 1;
end
else if Count = Last then
Done := True
else
Exit;
The case statement
case I of
1..5: Caption := 'Low';
6..9: Caption := 'High';
0, 10..99: Caption := 'Out of range';
else
Caption := '';
end;
is equivalent to the nested conditional
if I in [1..5] then
Caption := 'Low'
else if I in [6..10] then
Caption := 'High'
else if (I = 0) or (I in [10..99]) then
Caption := 'Out of range'
else
Caption := '';
Other examples of case statements:
case MyColor of
Red: X := 1;
Green: X := 2;
Blue: X := 3;
Yellow, Orange, Black: X := 0;
end;
case Selection of
Done: Form1.Close;
Compute: CalculateTotal(UnitCost, Quantity);
else
Beep;
end;