Conditional Action (IF-ELSEIF-ELSE-ENDIF)

The IF-ELSEIF-ELSE-ENDIF construct consists of conditional clauses in a pattern that use expressions to determine which actions to execute. The construct is flexible and allows you to define actions that should occur if certain conditions are true or not true.

Format

IF expression
		[action]...

		[ELSEIF expression
			[action]...]...

		[ELSE
			[action]...]
ENDIF

Conditional Clauses

Table 4–10 describes the clauses of a conditional construct.

Table 14. Conditional Clauses

Clause

Description

IF

Indicates the beginning of the conditional construction. Expression is required; an action is optional.

ELSEIF

Introduces an optional clause that includes a condition that is checked if the expression from the IF clause or previous ELSEIF clause evaluates to false. If the ELSEIF expression evaluates to true, the following set of actions is executed. You can specify multiple ELSEIF clauses in a conditional construct.

ELSE

Introduces an optional clause that includes a set of actions that are executed if none of the expressions in the preceding IF and ELSEIF clauses evaluate to true.

ENDIF

Indicates the end of the conditional construct.


where:

expression

is a condition that must evaluate to true for the specified actions to occur. See Section 5.

action

is any of the following:

Sequence of Conditional Action Processing

Conditional action processing occurs in the sequence specified in the conditional construct. For instance, in a simple conditional action construct, the processing would occur in the following sequence.

Clause

Expression Is True (Nonzero)

Expression Is Not True (Zero)

Step 1: IF

AMS performs the actions specified following the IF clause and proceeds to step 4.

  • AMS checks the ELSEIF clause, step 2.

  • If there is no ELSEIF clause, AMS proceeds to the ELSE clause, step 3.

  • If there is no ELSE clause, AMS proceeds to step 4.

Step 2: ELSEIF

AMS performs the actions specified following the ELSEIF clause and proceeds to step 4.

  • AMS checks subsequent ELSEIF clauses. Repeat step 2.

  • If there are no other ELSEIF clauses, AMS proceeds to the ELSE clause, step 3.

  • If there is no ELSE clause, AMS proceeds to step 4.

Step 3: ELSE

No expression is associated with the ELSE clause. If processing reaches this point, the IF clause and all ELSEIF clauses evaluated to false. The actions specified following the ELSE clause are performed.

Step 4: ENDIF

Conditional processing ends

  • After performing actions specified following either

    • An IF or ELSEIF clause when its expression is true

    • The ELSE clause

  • Without performing any actions when the IF condition and any ELSEIF conditions are false, and there is no ELSE clause