then statement if G2 evaluates the truth-value-expression to true; otherwise, it executes the else statement, if one exists, or the statement following the if-then, if no else exists. The syntax is:
if truth-value-expression
then statement
[else statement]
if x = y
then return 10 else return 12
x equals y; however, if x does not equal y, the program returns 12. You can nest
if-then statements by enclosing the nested if-then statement in a begin-end block. For example:
if x = y then
begin
if x = z then
return 10
else
return 12
end
else ...
x is not equal to y, G2 ignores the nested if-then statement and passes control to the else portion of the outer if statement. If x does equal y, G2 executes the nested if-then statement.
then clause contains a begin-end block immediately followed by an else clause, do not put a semicolon after the keyword end. Such a semicolon would terminate the scope of the if statement, causing the else clause to appear as a syntax error.