Copy link to clipboard
Copied
If i have this code:
var test: Boolean;
test = false;
if (2 == 2 == 1)
{
test = true;
}
trace (test);
Result: true.
var test: Boolean;
test = false;
if (2 == 2 == 2)
{
test = true;
}
trace (test);
Result: false
var test: Boolean;
test = false;
if (2 == 2 == 3)
{
test = true;
}
trace (test);
Result: false.
Why is that?
This is not a Math issue, it is a matter of how a condfitonal test is carried out. Conditions are tested as pairs (with a left to right hierarchy unless otherwise arranged using parentheses), meaning for 2 == 2 == whatever, first the test is performed to see if 2 == 2 ?, which is true, meaning the result evaluates as a "true". Then the next comparison is performed using the result of the first... which would be... true == whatever ?. which depends on "whatever" is. A 1 evaluates as true as
...Copy link to clipboard
Copied
This is not a Math issue, it is a matter of how a condfitonal test is carried out. Conditions are tested as pairs (with a left to right hierarchy unless otherwise arranged using parentheses), meaning for 2 == 2 == whatever, first the test is performed to see if 2 == 2 ?, which is true, meaning the result evaluates as a "true". Then the next comparison is performed using the result of the first... which would be... true == whatever ?. which depends on "whatever" is. A 1 evaluates as true as far as logic goes, but any other number does not, so true == 1 = true, true == 0,2,3,4,5.... = false
You will find nothing passes the test if you reverse the order of the numbers.
If you want to do compound conditional tests you are best to do it in pairs and/or use parentheses to define the order in which evaluations are managed.
Copy link to clipboard
Copied
Thanks.
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now