Order of Precedence: Difference between revisions
Category: Syntax
Lou Montana (talk | contribs) m (Some wiki formatting) |
Lou Montana (talk | contribs) m (Fix "braced expressions" line to a more comprehensive version) |
||
(One intermediate revision by the same user not shown) | |||
Line 22: | Line 22: | ||
* [[Variables]] | * [[Variables]] | ||
* Values | * Values | ||
* | * <sqf inline>()</sqf> / <sqf inline>[]</sqf> / <sqf inline>{}</sqf> / <sqf inline>""</sqf> / <sqf inline>''</sqf> -enclosed expressions | ||
|- | |- | ||
| style="text-align: center" | 10 | | style="text-align: center" | 10 | ||
Line 128: | Line 128: | ||
| <sqf>1 + 2 * 3</sqf> | | <sqf>1 + 2 * 3</sqf> | ||
| <sqf>1 + (2 * 3)</sqf> | | <sqf>1 + (2 * 3)</sqf> | ||
| result equals 7, and not 9 (see also {{ | | result equals 7, and not 9 (see also {{Link|https://en.wikipedia.org/wiki/Order_of_operations|PEMDAS}}) | ||
|- | |- | ||
| <sqf>sleep 10 + random 20</sqf> | | <sqf>sleep 10 + random 20</sqf> |
Latest revision as of 12:05, 2 September 2025
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
Precedence | Type of Operator | Examples |
---|---|---|
11 |
Nular operators (commands with no arguments):
|
|
10 |
Unary operators (commands with 1 argument):
|
|
9 | Hash-select operator | |
8 | Power operator | |
7 | ||
6 | ||
5 | N/A | |
4 |
Binary operators (commands with 2 arguments):
|
|
3 | ||
2 | Logical and operator | |
1 | Logical or operator |
Examples
Input | Process | Comment |
---|---|---|
result equals 7, and not 9 (see also PEMDAS) | ||
sleep 10 will return Nothing, then + random 20 will be calculated but not used. |