Arithmetic Expression
An arithmetic expression takes one of the following general forms:
expression
To
expression
expression
+
expression
expression
-
expression
expression
*
expression
expression
/
expression
expression
//
expression
or it is simply a numeric variable.
note
1.The
To
operator returns a list of numbers, whereas all the other arithmetic operators return a single number.2. The normal rules of associativity and precedence apply to the arithmetic operators. For example, (3 - 2 - 1) means ((3 - 2) - 1)=0 rather than (3 - (2 - 1))=2
Example
Consider numeric variables
VarA
, VarB
, VarC
having values 3
, 3
, 4
respectively.Expression | Value |
|---|---|
1 To VarA | List( 1, 2, 3 ) |
1 To VarA + VarB + VarC | List( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ) |
VarA + VarB + VarC | 10 |
VarA - VarB - VarC | -4 |
VarA * VarB + VarA * VarC | 21 |
VarA * ( VarB + VarC ) | 21 |
VarA* VarB / VarC | 2.25 |
VarA / VarB * VarC | 4 |
VarA // VarB | 1 |
VarA // VarC | 0 |
VarC // VarA | 1 |