View comments | RSS feed

&& logical AND operator

expression1 && expression2

Performs a Boolean operation on the values of both expressions. If expression1 and expression2 are both true, then true is returned; otherwise, false is returned.

Expression

Evaluates

true&&true

true

true&&false

false

false&&false

false

false&&true

false

Availability: ActionScript 1.0; Flash Player 4

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 - A Boolean result of the logical operation.

Example

The following example uses the logical AND (&&) operator to perform a test to determine if a player has won the game. The turns variable and the score variable are updated when a player takes a turn or scores points during the game. The script shows "You Win the Game!" in the Output panel when the player's score reaches 75 or higher in 3 turns or less.

var turns:Number = 2; 
var score:Number = 77; 
if ((turns <= 3) && (score >= 75)) { 
 trace("You Win the Game!"); 
} else { 
 trace("Try Again!"); 
} 
// output: You Win the Game! 

See also

! logical NOT operator, != inequality operator, !== strict inequality operator, || logical OR operator, == equality operator, === strict equality operator


Flash CS3


Comments


Fumio Nonaka said on Aug 26, 2007 at 10:26 AM :
[Returns]
Wrong: "Boolean - A Boolean result of the logical operation."
Correct: "Object - A Boolean value if both operands are members of the
Boolean data type. Otherwise, the result will be the value of either
expression."

See the comments of the following Flash 8 Documentation:
http://livedocs.adobe.com/flash/8/main/00001837.html
tderich said on Aug 29, 2007 at 9:31 AM :
Fumio - Thank you for your comment. The documentation is correct in the ActionScript 3.0 documentation:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#logical_AND. I've updated the AS2 source.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00001288.html