Prev | Current Page 135 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Using the grouping operators,
you can rewrite the previous problem like this:
var result:Float = ((21 * 2) + 5) - (4 / 2);
You are now left with a formula that is more pleasing to the eye and should be readable by those not
familiar with operator precedence. At the same time, you could decide to change the order of precedence
by moving the grouping operators and not the binary operators or values, such as:
var result:Float = (21 * ((2 + 5) - 4)) / 2;
The equation now reads as 2 + 5 = 7 ??“ 4 = 3 * 21 = 63 / 2 = 31.5. An entirely different result, altogether.
The Modulo Operator
One of the binary operators you may not be familiar with is the modulo operator ( % ). The purpose of the
modulo operator is to determine the remainder of a division. For example, if you wanted to find the
remainder of 10 divided by 3, you could use the expression:
remainder = 10 % 3;
While it may not seem very useful at first, the modulo operator can come in very handy when trying to
determine if a value is exactly divisible by another value.


Pages:
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147