---
name: "Order of Precedence"
type: topic
source: https://community.bistudio.com/wiki/Order_of_Precedence
revid: 376136
updated: 2025-09-02T10:05:38Z
---

# Order of Precedence

Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression.

#### Precedence Overview

> [!NOTE]
> - Highest precedence means highest priority
> - Associativity is (then) done from left to right, for example `3 + 5 + 8` will be processed as `((3 + 5) + 8)`

| Precedence | Type of Operator | Examples |
|---|---|---|
| 11 | Nular operators (commands with no arguments):<br>- `commandName` | - [Variables](../topics/Variables.md)<br>- Values<br>- `()` / `[]` / `{}` / `""` / `''` -enclosed expressions |
| 10 | Unary operators (commands with 1 argument):<br>- `commandName` a | * [+a](../commands/~2B.md)<br>- [-a](../commands/-.md)<br>- [+array](../commands/~2B.md)<br>- [! b](../commands/~21_a.md)<br>- [not b](../commands/not.md) |
| 9 | Hash-select operator | - [array # index](../commands/a_hash_b.md) |
| 8 | Power operator | - [a ^ b](../commands/a_~5E_b.md) |
| 7 | - [Number](../topics/Number.md) multiplication, division and remainder<br>- [atan2](../commands/atan2.md)<br>- [Config](../topics/Config.md) access ([/](../commands/a_~2F_b.md)) | * [a * b](../commands/a_~2A_b.md)<br>- [a / b](../commands/a_~2F_b.md)<br>- [a % b](../commands/a_~25_b.md)<br>- [a mod b](../commands/mod.md)<br>- [a / b](../commands/a_~2F_b.md)<br>- [a atan2 b](../commands/atan2.md) |
| 6 | - [Number](../topics/Number.md) addition and subtraction<br>- [Array](../topics/Array.md) addition and subtraction<br>- [String](../topics/String.md) addition<br>- [min](../commands/min.md) and [max](../commands/max.md) commands | * [a + b](../commands/~2B.md)<br>- [a - b](../commands/-.md)<br>- [arr1 + arr2](../commands/~2B.md)<br>- [arr1 - arr2](../commands/-.md)<br>- [str1 + str2](../commands/~2B.md)<br>- [a min b](../commands/min.md)<br>- [a max b](../commands/max.md) |
| 5 | - [else](../commands/else.md) ([if](../commands/if.md)-[then](../commands/then.md)-[else](../commands/else.md) structure) | N/A |
| 4 | Binary operators (commands with 2 arguments):<br>- a `commandName` b | - [setDir](../commands/setDir.md)<br>- [switch colon (:)](../commands/a_~3A_b.md) |
| 3 | - [==](../commands/a_~3D~3D_b.md) and [!=](../commands/a_~21~3D_b.md) comparisons<br>- [Number](../topics/Number.md) comparisons<br>- [Config](../topics/Config.md) access ([>>](../commands/config_greater_greater_name.md)) | - [a == b](../commands/a_~3D~3D_b.md)<br>- [a != b](../commands/a_~21~3D_b.md)<br>- [a > b](../commands/a_greater_b.md)<br>- [a < b](../commands/a_less_b.md)<br>- [a >= b](../commands/a_greater~3D_b.md)<br>- [a <= b](../commands/a_less~3D_b.md)<br>- [config >> name](../commands/config_greater_greater_name.md) |
| 2 | Logical [and](../commands/and.md) operator | - [&&](../commands/a_~26~26_b.md)<br>- [and](../commands/and.md) |
| 1 | Logical [or](../commands/or.md) operator | - [\|\|](../commands/a_or_b.md)<br>- [or](../commands/or.md) |

#### Examples

| Input | Process | Comment |
|---|---|---|
| ```sqf<br>1 + 2 * 3<br>``` | ```sqf<br>1 + (2 * 3)<br>``` | result equals 7, and not 9 (see also [PEMDAS](https://en.wikipedia.org/wiki/Order_of_operations)) |
| ```sqf<br>sleep 10 + random 20<br>``` | ```sqf<br>(sleep 10) + random 20<br>``` | `sleep 10` will return [Nothing](../topics/Nothing.md), then `+ random 20` will be calculated but not used.<br>`sleep (10 + random 20)` should be used instead |

<sub>Source: [BI Community Wiki — Order of Precedence](https://community.bistudio.com/wiki/Order_of_Precedence) (revision 376136).</sub>
