User Guide
162 ActionScript language elements
|| logical OR operator
expression1 || expression2
Evaluates expression1 (the expression on the left side of the operator) and returns true if
the expression evaluates to
true. If expression1 evaluates to false, expression2 (the
expression on the right side of the operator) is evaluated. If
expression2 evaluates to false,
the final result is
false; otherwise, it is true.
If you use a function call as
expression2, the function will not be executed by that call if
expression1 evaluates to true.
The result is
true if either or both expressions evaluate to true; the result is false only if
both expressions evaluate to
false. You can use the logical OR operator with any number of
operands; if any operand evaluates to
true, the result is true.
Availability: ActionScript 1.0; Flash Lite 1.0
Operands
expression1 : Number - A Boolean value or an expression that converts to a Boolean value.
expression2 : Number - A Boolean value or an expression that converts to a Boolean value.
Returns
Boolean - The result of the logical operation.
Example
The following example uses the logical OR (||) operator in an if statement. The second
expression evaluates to
true, so the final result is true:
var x:Number = 10;
var y:Number = 250;
var start:Boolean = false;
if ((x > 25) || (y > 200) || (start)) {
trace("the logical OR test passed"); // output: the logical OR test passed
}
The message the logical OR test passed appears because one of the conditions in the if
statement is true (
y>200). Although the other two expressions evaluate to false, as long as
one condition evaluates to
true, the if block is executed.