In the preceding examples, the assignment is made to a simple constant. However, any valid expression can be used instead. A simple expression might be a variable name combined with an operator and a constant.
Operators |
Perform mathematical, string, and logical operations on two surrounding values. |
Operands |
Surrounding values on which specified operations are performed. |
Example
To assign the variable NUMBER2 to be NUMBER plus 1:
NUMBER2 = NUMBER + 1 |
In this example, + is the operator, and NUMBER and 1 are the operands. NUMBER is interpreted as a variable name, and 1 is interpreted as a numeric constant. If NUMBER contains 4, then after the above statement, NUMBER2 will contain 5.
Another simple expression might involve an intrinsic function.
Functions |
Perform mathematical, string, and logical operations on a value passed within parentheses. |
For example, to assign the variable ROOT to the square root of NUMBER:
ROOT = SQRT(NUMBER) |
In this example, SQRT is the function and NUMBER is the value passed to it. If NUMBER contains 4, then after the above statement, ROOT will contain 2.
Multiple operators and functions can be combined in an expression to evaluate to a single value. For example, to assign NUMBER3 to be 1 plus the square root of NUMBER:
NUMBER3 = SQRT(NUMBER) + 1 |
After the above statement, NUMBER3 will contain 3. Note that this is different from:
NUMBER3 = SQRT(NUMBER + 1) |
which will return into NUMBER3 the square root of 5, or 2.236.
Valid expressions can therefore be as simple as a constant or a single variable name, or they can consist of multiple operations to be evaluated at run time.
See Also