# Precedence

Precedence is the set of rules imposed upon the evaluation
of components of an expression that are not otherwise overridden by
the presence of parentheses.

Based on the operation, expressions are evaluated from
left-to-right (left-associative), from right-to-left (right-associative),
or with no association (nonassociative). For example, multiplication
and division are left-associative. The arithmetic expression below
evaluates left-to-right:

```
x = 9 / 3 * 2
```
This first divides 9 by 3, yielding 3, which is then multiplied
by 2, yielding the result 6. This expression evaluated as a right
association returns the result 1.5.

Logical operations are nonassociative.
For example, the expression below does not compile:

```
x = 1 < x < 3
```
Adding parentheses makes it a valid expression:

```
x = (1 < x) < 3
```
Adding the parentheses, however, does not return the results
of `(1 The above two examples both evaluate as 1. In the first
example, `(99 Below is a list of operations, precedence and associativity:

| Symbol | Priority | Operation | Association |
| --- | --- | --- | --- |
| () | 0 (high) | Parentheses | None |
| [] | 1 | Substring extraction | None |
| <> | 1 | Dynamic array reference | None |
| ^ | 2 | Exponentiation | Left |
| ** | 2 | Exponentiation | Left |
| * | 3 | Multiplication | Left |
| / | 3 | Division | Left |
| \ | 3 | Remainder | Left |
| + | 4 | Addition | Left |
| - | 4 | Subtraction | Left |
| + | 4 | Unary positive | Right |
| - | 4 | Unary negative | Right |
| mask | 5 | String masking | Left |
| cat | 6 | Concatenation | Right |
| : | 6 | Concatenation | Right |
| eq, = | 7 | Logical equal | None |
| ne, # | 7 | Not equal | None |
| <> | 7 | Not equal | None |
| lt, | 7 | Greater than | None |
| ge, >= | 7 | Greater than or = | None |
| match | 7 | Pattern match | None |
| matches | 7 | Pattern match | None |
| and, & | 8 | Logical and | Left |
| or, ! | 8 | Logical or | Left |
Expressions are evaluated in order of precedence unless
placed within parentheses. `10+2*10` is evaluated as
30. Expressions within the innermost parentheses are evaluated first. `(10+2)*10` evaluates as 120.

## See also

- [() reserved characters](https://d3codex.com/pickbasic-flashbasic/parenthesis-reserved-characters/)
- [* arithmetic operator](https://d3codex.com/pickbasic-flashbasic/asterisk-arithmetic-operator/)
- [*= assignment operator](https://d3codex.com/pickbasic-flashbasic/asterisk-equals-assignment-operator/)
- [+ arithmetic operator](https://d3codex.com/pickbasic-flashbasic/plus-arithmetic-operator/)
- [+= assignment operator](https://d3codex.com/pickbasic-flashbasic/plus-equals-assignment-operator/)
- [- arithmetic operator](https://d3codex.com/pickbasic-flashbasic/minus-arithmetic-operator/)
- [-= assignment operator](https://d3codex.com/pickbasic-flashbasic/minus-equals-assignment-operator/)
- [/= assignment operator](https://d3codex.com/pickbasic-flashbasic/slash-equals-assignment-operator/)
- [:= assignment operator](https://d3codex.com/pickbasic-flashbasic/colon-equals-assignment-operator/)
- [Arithmetic expressions](https://d3codex.com/pickbasic-flashbasic/arithmetic-expressions/)
- [Arithmetic operators](https://d3codex.com/pickbasic-flashbasic/arithmetic-operators/)
- [Boolean evaluation](https://d3codex.com/pickbasic-flashbasic/boolean-evaluation/)
- [Logical expressions](https://d3codex.com/pickbasic-flashbasic/logical-expressions/)
- [Relational operators](https://d3codex.com/pickbasic-flashbasic/relational-operators/)
- [\= assignment operator](https://d3codex.com/pickbasic-flashbasic/backslash-equals-assignment-operator/)

---
Source: https://d3codex.com/pickbasic-flashbasic/precedence/ - part of the D3Codex reference.
