else if
Top  Previous  Next


SWiSH Player Support
SWF4 or later - Supported Internally

Syntax
if (condition){
statement(s);
} else if (condition){
statement(s);
}

Arguments
condition: An expression that evaluates to true or false.
statement(s): An alternative series of statements to run if the condition specified in the if statement is false.

Returns
Nothing.

Description
Action: Used to introduce second (or more) conditional test(s) if initial condition equates to false. Once a condition evaluates to true, after the associated statements have been executed, control passes to the end of the if / else if / else if sequence. This can be used to prevent too many nested levels if standard else construct is used.

Note: An if conditional can contain multiple else if actions and one optional else action after the last else if listed.

Sample
if (this._X > maxX) {
    this._X = maxX;
    dx = -dx;   // bounce of right wall
}
 else if (this._X < minX) {
    this._X = minX;
    dx = -dx;
}


The above example is easier to read than the following (equivalent code)

if (this._X > maxX) {
    this._X = maxX;
    dx = -dx;   // bounce of right wall
}
 else {
    if (this._X < minX) {
        this._X = minX;
     dx = -dx;
    }

}


See also

if; else