Order of Precedence: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Some wiki formatting) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
Line 1: | Line 1: | ||
<onlyinclude> | <onlyinclude> | ||
Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression. | 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 === <!--- Level 3 because it's transcluded into Operators page ---> | === Precedence Overview === <!--- Level 3 because it's transcluded into Operators page ---> | ||
{{Feature | Informative | | {{Feature | Informative | | ||
* Highest precedence means highest priority | * Highest precedence means highest priority | ||
Line 29: | Line 29: | ||
* {{hl|commandName}} a | * {{hl|commandName}} a | ||
| {{Columns|2| | | {{Columns|2| | ||
* [[+ |+a]] | * [[+|+a]] | ||
* [[- | -a]] | * [[-|-a]] | ||
* [[+ | +array]] | * [[+|+array]] | ||
* [[! | * [[! a|! b]] | ||
* [[not | not b]] | * [[not|not b]] | ||
}} | }} | ||
|- | |- | ||
Line 39: | Line 39: | ||
| Hash-select operator | | Hash-select operator | ||
| | | | ||
* [[ | * [[a hash b|array # index]] | ||
|- | |- | ||
| style="text-align: center" | 8 | | style="text-align: center" | 8 | ||
Line 67: | Line 67: | ||
* [[min]] and [[max]] commands | * [[min]] and [[max]] commands | ||
| {{Columns|2| | | {{Columns|2| | ||
* [[+ | a + b]] | * [[+|a + b]] | ||
* [[- | a - b]] | * [[-|a - b]] | ||
* [[+ | arr1 + arr2]] | * [[+|arr1 + arr2]] | ||
* [[- | arr1 - arr2]] | * [[-|arr1 - arr2]] | ||
* [[+ | str1 + str2]] | * [[+|str1 + str2]] | ||
* [[min | a min b]] | * [[min|a min b]] | ||
* [[max | a max b]] | * [[max|a max b]] | ||
}} | }} | ||
|- | |- | ||
Line 87: | Line 87: | ||
| | | | ||
* [[setDir]] | * [[setDir]] | ||
* [[ | * [[a : b|switch colon (:)]] | ||
|- | |- | ||
| style="text-align: center" | 3 | | style="text-align: center" | 3 | ||
Line 98: | Line 98: | ||
* [[a == b]] | * [[a == b]] | ||
* [[a != b]] | * [[a != b]] | ||
* [[ | * [[a greater b|a > b]] | ||
* [[ | * [[a less b|a < b]] | ||
* [[ | * [[a greater= b|a >= b]] | ||
* [[ | * [[a less= b|a <= b]] | ||
}} | }} | ||
* [[ | * [[config greater greater name|config >> name]] | ||
|- | |- | ||
| style="text-align: center" | 2 | | style="text-align: center" | 2 | ||
Line 118: | Line 118: | ||
|} | |} | ||
== Examples == | |||
=== Examples === | |||
{| class="wikitable" | {| class="wikitable" | ||
! Input | ! Input | ||
Line 125: | Line 127: | ||
|- | |- | ||
| <sqf>1 + 2 * 3</sqf> | | <sqf>1 + 2 * 3</sqf> | ||
| | | <sqf>1 + (2 * 3)</sqf> | ||
| result equals 7, and not 9 (see also {{Wikipedia|Order of operations|PEMDAS}}) | | result equals 7, and not 9 (see also {{Wikipedia|Order of operations|PEMDAS}}) | ||
|- | |- | ||
Line 134: | Line 135: | ||
<sqf inline>sleep (10 + random 20)</sqf> should be used instead | <sqf inline>sleep (10 + random 20)</sqf> should be used instead | ||
|} | |} | ||
</onlyinclude> | </onlyinclude> | ||
[[Category:Syntax]] | [[Category:Syntax]] |
Revision as of 10:48, 23 August 2022
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. |