Computational |
General Comments: The computational operators perform a mathematical function on a value or values, and return a single value. |
Operator
|
What does it do? |
Example/Explanation |
+ |
Adds two values together |
counter+2
Returns the sum of the counter plus 2 |
- |
Subtracts one value from another |
counter-2
Returns the sum of the counter minus 2 |
* |
Multiplies two values |
counter*10
Returns the result of the variable times 10 |
/ |
Divides the value on the left by the one on the right and returns the result |
counter/2
Divides the current value of the counter by 2 and returns the result |
++X |
Increments the value, and then returns the result |
++counter
Looks at the current value of the counter, increments it by one, and then returns the result. If the counter has a value of 3, this equation returns the value of 4. |
X++ |
Returns the value, and then increments the value |
counter++
Returns the value of the counter, then increments the counter. If the counter has a value of 3, this equation returns the value of 3, then sets the counter value to 4. |
--X |
Decreases the value, and then returns the result |
--counter
Looks at the current value of the counter, decreases it by one, and then returns the result. If the counter has a value of 7, this equation returns the value of 6. |
X-- |
Returns the value, and then decreases the value |
counter--
Returns the value of the counter, then decrease the counter value. If the counter has a value of 7, this equation returns the value of 7, then sets the counter value to 6. |