Prev | Current Page 140 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


An issue arises if you wish to stack more than two expressions using the logical AND and OR operators.
Looking at the next example, see if you can guess what the outcome should be.
var myBool : Bool = (1 < 2) & & (2 == 2) & & (2 > = 4) || (4 < 3);
If you guessed correctly, you should have expected false to be the answer. The reason for this is that,
when grouping logical operators, any adjacent expressions joined by AND operators will all have to
return true for the overall result to be true, while adjacent OR operators will only require one
expression to return true . To see this more clearly, it helps to picture the expressions enclosed within the
group operators ( and ) .
var myBool : Bool = (1 < 2 & & 2 == 2 & & 2 > = 4) || (4 < 3);
As you can see, each expression joined by the logical AND operator is reliant on its neighbor, while the
logical OR operator separates the left - hand expression from its right - hand neighbor.
You will look more closely at logical comparison operators when you examine the if.


Pages:
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152