The elsif Statement
Syntax
if (condition-1) {
[ statements-1 ]
}
elsif (condition-2) {
[ statements-2 ]
}
else {
[ statements-3 ]
}
An elsif
statement is used to evaluate a subsequent
condition after a preceding if statement
evaluates to false
. In the example above, when condition-1
evaluates to false, then statements-1 are skipped and condition-2
is checked. When condition-2 evaluates true, then statements-2
are executed. When condition-2 evaluates false, then
statements-2 are skipped and statements-3 are executed.
As with if, an elsif
clause does not need to be followed by
an else statement. However, any else statement
must be the last statement in an elsif
chain. An arbitrary number of
elsif
statements can be chained together to create a series of
conditional checks and statements.
Example
if (&User-Name == "bob") {
reject
}
elsif (&User-Name == "doug") {
ok
}