what does the operators evaluate on instructions?
like:
var flag:Boolean=true;
flag && trace("1") && trace("2") && trace("3");
output:
1
2
3
var flag:Boolean=true;
flag && trace("1") || trace("2") || trace("3");
output
1
The or operator breaks the sentence under idk what circumstances…
Edit: ok, now i see how the sentence works with the operators, but is any instruction that doesn’t have a return value valuated as true?
And it appears u can’t evaluate any instruction u want, like:
private function any():void{
true && return;
}
that will throw a compilation error.
Edit: In this case, it behaves different to the second example:
true && one() || two() || three();
the functions
private function one():void{
trace("1");
}
private function two():void{
trace("2");
}
private function three():void{
trace("3");
}
output:
1
2
3
Edit: Assigning values:
var a:int;
(a=1) || trace("1");
(a=2) && trace("2");
output:
2
Edit:
|| Returns expression1 if it is true or can be converted to true, and expression2 otherwise
&& “Returns expression1 if it is false or can be converted to false, and expression2 otherwise. Examples of values that can be converted to false are 0, NaN, null, and undefined”.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/operators.html#logical_OR
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/operators.html#logical_AND
ActionScript 3 is an ECMAScript variant, which means it’s based off the same standard as JavaScript.
Because of this
&&and||are not similar to other C-style languages.a || breturnsaifais truthy, otherwise it returnsb.a && breturnsaifais falsey, otherwise it returnsb.This makes
||essentially equivalent toa ? a : b, and&&essentially equivalent to!a ? a : b.They also have a short-circuit evaluation mechanism. If the first argument is to be returned, the second argument is not executed.