{"name":"Order of Precedence","title":"Order of Precedence","type":"topic","url":"https://community.bistudio.com/wiki/Order_of_Precedence","revid":376136,"updated":"2025-09-02T10:05:38Z","aliases":[],"markdown":"Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression.\n\n#### Precedence Overview\n\n> [!NOTE]\n> - Highest precedence means highest priority\n> - Associativity is (then) done from left to right, for example `3 + 5 + 8` will be processed as `((3 + 5) + 8)`\n\n| Precedence | Type of Operator | Examples |\n|---|---|---|\n| 11 | Nular operators (commands with no arguments):<br>- `commandName` | - Variables<br>- Values<br>- `()` / `[]` / `{}` / `\"\"` / `''` -enclosed expressions |\n| 10 | Unary operators (commands with 1 argument):<br>- `commandName` a | * +a<br>- -a<br>- +array<br>- ! b<br>- not b |\n| 9 | Hash-select operator | - array # index |\n| 8 | Power operator | - a ^ b |\n| 7 | - Number multiplication, division and remainder<br>- atan2<br>- Config access (/) | * a * b<br>- a / b<br>- a % b<br>- a mod b<br>- a / b<br>- a atan2 b |\n| 6 | - Number addition and subtraction<br>- Array addition and subtraction<br>- String addition<br>- min and max commands | * a + b<br>- a - b<br>- arr1 + arr2<br>- arr1 - arr2<br>- str1 + str2<br>- a min b<br>- a max b |\n| 5 | - else (if-then-else structure) | N/A |\n| 4 | Binary operators (commands with 2 arguments):<br>- a `commandName` b | - setDir<br>- switch colon (:) |\n| 3 | - == and != comparisons<br>- Number comparisons<br>- Config access (>>) | - a == b<br>- a != b<br>- a > b<br>- a < b<br>- a >= b<br>- a <= b<br>- config >> name |\n| 2 | Logical and operator | - &&<br>- and |\n| 1 | Logical or operator | - \\|\\|<br>- or |\n\n#### Examples\n\n| Input | Process | Comment |\n|---|---|---|\n| ```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)) |\n| ```sqf<br>sleep 10 + random 20<br>``` | ```sqf<br>(sleep 10) + random 20<br>``` | `sleep 10` will return Nothing, then `+ random 20` will be calculated but not used.<br>`sleep (10 + random 20)` should be used instead |","sections":[{"heading":null,"level":1,"markdown":"Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression."},{"heading":"Precedence Overview","level":4,"markdown":"> [!NOTE]\n> - Highest precedence means highest priority\n> - Associativity is (then) done from left to right, for example `3 + 5 + 8` will be processed as `((3 + 5) + 8)`\n\n| Precedence | Type of Operator | Examples |\n|---|---|---|\n| 11 | Nular operators (commands with no arguments):<br>- `commandName` | - Variables<br>- Values<br>- `()` / `[]` / `{}` / `\"\"` / `''` -enclosed expressions |\n| 10 | Unary operators (commands with 1 argument):<br>- `commandName` a | * +a<br>- -a<br>- +array<br>- ! b<br>- not b |\n| 9 | Hash-select operator | - array # index |\n| 8 | Power operator | - a ^ b |\n| 7 | - Number multiplication, division and remainder<br>- atan2<br>- Config access (/) | * a * b<br>- a / b<br>- a % b<br>- a mod b<br>- a / b<br>- a atan2 b |\n| 6 | - Number addition and subtraction<br>- Array addition and subtraction<br>- String addition<br>- min and max commands | * a + b<br>- a - b<br>- arr1 + arr2<br>- arr1 - arr2<br>- str1 + str2<br>- a min b<br>- a max b |\n| 5 | - else (if-then-else structure) | N/A |\n| 4 | Binary operators (commands with 2 arguments):<br>- a `commandName` b | - setDir<br>- switch colon (:) |\n| 3 | - == and != comparisons<br>- Number comparisons<br>- Config access (>>) | - a == b<br>- a != b<br>- a > b<br>- a < b<br>- a >= b<br>- a <= b<br>- config >> name |\n| 2 | Logical and operator | - &&<br>- and |\n| 1 | Logical or operator | - \\|\\|<br>- or |"},{"heading":"Examples","level":4,"markdown":"| Input | Process | Comment |\n|---|---|---|\n| ```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)) |\n| ```sqf<br>sleep 10 + random 20<br>``` | ```sqf<br>(sleep 10) + random 20<br>``` | `sleep 10` will return Nothing, then `+ random 20` will be calculated but not used.<br>`sleep (10 + random 20)` should be used instead |"}],"categories":["Syntax"],"groups":["Scripting"]}