Order of Precedence: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Created page with "== Introduction == Order of operations, also called operator precedence, is a set of rules specifying which procedures should be performed first in a mathematical expression....")
 
m (Fix Wikipedia link)
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Introduction ==
<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 --->


{{Feature | Informative |
{{Feature | Informative |
* Highest precedence means highest priority
* Highest precedence means highest priority
* Associativity is (then) done from left to right, for example {{Inline code|3 + 5 + 8}} will be processed as {{Inline code|((3 + 5) + 8)}}
* Associativity is (then) done from left to right, for example <sqf inline>3 + 5 + 8</sqf> will be processed as <sqf inline>((3 + 5) + 8)</sqf>
}}
}}


Line 16: Line 18:
|
|
Nular operators (commands with no arguments):
Nular operators (commands with no arguments):
* <tt>commandName</tt>
* {{hl|commandName}}
|
|
* [[Variables]]
* [[Variables]]
Line 25: Line 27:
|
|
Unary operators (commands with 1 argument):
Unary operators (commands with 1 argument):
* <tt>commandName</tt> a
* {{hl|commandName}} a
|
| {{Columns|2|
* [[+ |+a]]
* [[+|+a]]
* [[- | -a]]
* [[-|-a]]
 
* [[+|+array]]
* [[+ | +array]]
* [[! a|! b]]
 
* [[not|not b]]
* [[!_a | !b]]
}}
* [[not | not b]]
|-
|-
| style="text-align: center" | 9
| style="text-align: center" | 9
| Hash-select operator
| Hash-select operator
|
|
* [[a_hash_b| array # index]]
* [[a hash b|array # index]]
|-
|-
| style="text-align: center" | 8
| style="text-align: center" | 8
Line 49: Line 50:
* [[Number]] multiplication, division and remainder
* [[Number]] multiplication, division and remainder
* [[atan2]]
* [[atan2]]
* [[Config]] access ([[config / name|/]])
* [[Config]] access ([[a / b|/]])
|
| {{Columns|2|
* [[a * b]]
* [[a * b]]
* [[a / b]]
* [[a / b]]
* [[a % b]]
* [[a % b]]
* [[mod | a mod b]]
* [[mod | a mod b]]
 
* [[a / b]]
* [[config / name]]
 
* [[atan2| a atan2 b]]
* [[atan2| a atan2 b]]
}}
|-
|-
| style="text-align: center" | 6
| style="text-align: center" | 6
Line 66: Line 66:
* [[String]] addition
* [[String]] addition
* [[min]] and [[max]] commands
* [[min]] and [[max]] commands
|
| {{Columns|2|
* [[+ | a + b]]
* [[+|a + b]]
* [[- | a - b]]
* [[-|a - b]]
 
* [[+|arr1 + arr2]]
* [[+ | arr1 + arr2]]
* [[-|arr1 - arr2]]
* [[- | arr1 - arr2]]
* [[+|str1 + str2]]
 
* [[min|a min b]]
* [[+ | str1 + str2]]
* [[max|a max b]]
 
}}
* [[min | a min b]]
* [[max | a max b]]
|-
|-
| style="text-align: center" | 5
| style="text-align: center" | 5
Line 86: Line 84:
|
|
Binary operators (commands with 2 arguments):
Binary operators (commands with 2 arguments):
* a <tt>commandName</tt> b
* a {{hl|commandName}} b
|
|
* [[setDir]]
* [[setDir]]
* [[a_:_b |switch colon(:)]]
* [[a : b|switch colon (:)]]
|-
|-
| style="text-align: center" | 3
| style="text-align: center" | 3
Line 97: Line 95:
* [[Config]] access ([[config greater greater name|&gt;&gt;]])
* [[Config]] access ([[config greater greater name|&gt;&gt;]])
|
|
{{Columns|2|
* [[a == b]]
* [[a == b]]
* [[a != b]]
* [[a != b]]
* [[a_greater_b| a &gt; b]]
* [[a greater b|a &gt; b]]
* [[a_less_b| a &lt; b]]
* [[a less b|a &lt; b]]
* [[a_less=_b| a &gt;= b]]
* [[a greater= b|a &gt;= b]]
* [[a_less=_b| a &lt;= b]]
* [[a less= b|a &lt;= b]]
 
}}
* [[config_greater_greater_name | config >> name]]
* [[config greater greater name|config >> name]]
|-
|-
| style="text-align: center" | 2
| style="text-align: center" | 2
Line 119: Line 118:
|}
|}


[[Category:Scripting Topics]]
 
=== Examples ===
 
{| class="wikitable"
! Input
! Process
! Comment
|-
| <sqf>1 + 2 * 3</sqf>
| <sqf>1 + (2 * 3)</sqf>
| 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>
| <sqf inline>sleep 10</sqf> will return [[Nothing]], then <sqf inline>+ random 20</sqf> will be calculated but not used.<br>
<sqf inline>sleep (10 + random 20)</sqf> should be used instead
|}
</onlyinclude>
 
 
[[Category:Syntax]]

Latest revision as of 23:52, 23 February 2023

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

  • 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):

  • commandName
10

Unary operators (commands with 1 argument):

  • commandName a
9 Hash-select operator
8 Power operator
7
6
5 N/A
4

Binary operators (commands with 2 arguments):

  • a commandName b
3
2 Logical and operator
1 Logical or operator


Examples

Input Process Comment
1 + 2 * 3
1 + (2 * 3)
result equals 7, and not 9 (see also PEMDAS)
sleep 10 + random 20
(sleep 10) + random 20
sleep 10 will return Nothing, then + random 20 will be calculated but not used.

sleep (10 + random 20) should be used instead