Arithmetic operators form arithmetic expressions which BASIC+ evaluates according to a strict order of priority.
result = expression [operator expression …]
Priority | Operator | Keyboard Symbol |
---|---|---|
high 1 | unary plus | + |
1 | unary minus | - |
2 | exponentiation | ** |
3 | multivalued multiplication | *** |
3 | multivalued division | /// |
3 | multiplication | * |
3 | division | / |
4 | multivalued addition | +++ |
4 | multivalued subtraction | — |
4 | addition | + |
4 | subtraction | - |
5 | multivalued concatenation | ::: |
low 5 | concatenation | : |
The valid arithmetic operators in BASIC+ are listed in the chart above.
An expression may have more than one operator. Each operation has a priority rating. BASIC+ scans the entire expression and begins the evaluation with the operator that has the highest priority. If two or more operators have the same priority in a given expression, evaluation proceeds from left to right.
Parentheses may be used to alter the order of the priority. Expressions that are enclosed within parentheses are evaluated prior to expressions without parentheses. Parentheses may also be used anywhere in an expression to clarify its order or to increase readability of the program.
24 /2 * 4
The result will be 48. Multiplication and division have the same priority.
24 / ( 2 * 4 ) = 3
The result will be 3. The expression within the parentheses is evaluated first.