Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript language elements > Operators > || 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 Player 4
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.
Boolean - The result of the logical operation.
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 executes.
The following example demonstrates how using a function call as expression2 can lead to unexpected results. If the expression on the left of the operator evaluates to true, that result is returned without evaluating the expression on the right (the function fx2() is not called).
function fx1():Boolean {
trace("fx1 called");
return true;
}
function fx2():Boolean {
trace("fx2 called");
return true;
}
if (fx1() || fx2()) {
trace("IF statement entered");
}
The following is sent to the Output panel: fx1 called IF statement entered
! logical NOT operator, != inequality operator, !== strict inequality operator, && logical AND operator, == equality operator, === strict equality operator
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001292.html