Firebird 2.0
PSQL Reference
Manual

IF THEN ELSE STATEMENT

Pupose

Tests a condition, and if it evaluates to TRUE performs the statement or block following THEN; otherwise, it performs the statement or block following ELSE, if present.

Syntax

<if_then_else_stmt> ::=
   IF <psql_condition> THEN <psql_statement>
   [ ELSE <psql_statement> ]


Element
Description
psql_condition
A PSQL condition. See the section on Conditions for more information.
psql_statement
A PSQL statement. Often this will be a compound statement.

Semantics

The condition is evaluated and if it evaluates to TRUE the statement in the THEN clause is executed. If it is not TRUE, i.e. It evaluates to FALSE or to NULL, and an ELSE clause is present, then the statement in the ELSE clause is executed.

IF statements can be nested, i.e. The statements in the THEN or ELSE clauses can be IF statements also. If the THEN clause contains a IF THEN ELSE statement, then that ELSE clause is deemed to be part of the nested IF, just as in nearly all other programming languages. Enclose the nested if in a compound statement if you want the ELSE clause to refer to the enclosing IF statement.

Examples

The below examples show valid uses of the IF statement:

   IF (a>23) THEN a = a – 1;
   IF (myname='Paul') THEN a = a + 1; ELSE a = i;


See also

WHEN DO statement


previous page goto index next page

Legal information