<< Click to Display Table of Contents >> Navigation: Concordance Programming Fundamentals > Declaring and using a Variable > Performing Math with Variables |
You can also assign numerical values to a variable by using mathematical operators such as addition(+), subtraction (-), multiplication (*) and division (/). Consider the following valid programming statements:
x = y + 2; |
This statement adds the value of 2 and y, and assigns that value to x.
theAreaOfMyCircle = 3.1415 * r * r; |
This statement multiplies the variable r to itself, multiplies that value to 3.1415, and then assigns that value to theAreaofMyCircle.
x = x + 17; |
The third statement is somewhat more tricky. From a programming standpoint however, the statement merely adds 17 to the current value of x, and then stores that new value in x. After processing the statement, x now equals 17 more than it did previously.
Finally, you can assign a value to a variable using a function.
x = SomeRandomFunction(y, z, 17); |
For more information, see About CPL Functions.
For more information on using arethmetic operations, see Operators and Operands in the CPL Language reference.