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


Version 8

Comments


Fumio Nonaka said on Oct 16, 2005 at 12:26 PM :
[Returns]
[Wrong]: "Boolean - A Boolean result of the logical operation."
[Correct]: "Object - The value of either of two operands."
Thais Derich said on Mar 7, 2006 at 1:11 PM :
Returns - A Boolean value if both operands are members of the Boolean data type. Otherwise, the result will be the value of either expression.

 

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

Current page: http://livedocs.adobe.com/flash/8/main/00001837.html