| OP | Name | Example | Description |
|---|---|---|---|
+
|
Addition | x+y
|
Add x and y.
|
-
|
Subtraction | x-y
|
Subtract y from x.
|
*
|
Multiplication | x*y
|
Multiply x times y.
|
/
|
Division | x/y
|
Divide x by y.
|
%
|
Modulo | x%y
|
Remainder of x/y
|
++
|
Increment | x++ or ++x
|
Increase variable by 1 |
--
|
Decrement | x-- or --x
|
Decrease variable by 1 |
-
|
Unary negation | -x
|
Negate the value of x
|
Most of these are extremely straightforward and don't even deserve discussion. A couple of them need some clarification, though.
Modulo or Remainder
This calculates the remainder of the division of its two parameters. Oric BASIC doesn't have it, but Pascal users will be familiar with it, as the Mod operator.
Increment and Decrement Operators
These two are two very useful operators. Given a variable, they increment or decrement its contents by 1. The ++ or -- operator can be put before or after a variable. It behaves differently, depending on its position. When put before a variable, it changes the variable's value before that variable is used in the expression. If put after a variable, it alters its value after the variable has been used in the expression. This sounds obscure, and requires an example (or two):
Assume we have two variables, x=10 and y=20. We calculate the expression x=x+(++y). The contents of y are incremented before the variable is used, so the result will be x=10+21, or x=31. The value of y is 21.
Now let's again assume x=10 and y=20. In calculating x=x+(y++), the contents of y are used before it gets incremented. Thus, x=10+20, or x=30. The value of y at the end of the calculation is again 21, but the result of the expression is not the same. This double syntax comes very handy when programming loops.
Unary Negation
This is no other than our very own - operator, as used on single operands. For example, assuming x=10, the result of -x is -10. This should be simple enough.

Add new comment