Order of Precedence: Difference between revisions
Jump to navigation
Jump to search
m (moved onlyInclude) |
m (added examples) |
||
Line 120: | Line 120: | ||
* [[or]] | * [[or]] | ||
|} | |} | ||
== Examples == | |||
{| class="wikitable" | |||
! Input | |||
! Process | |||
! Comment | |||
|- | |||
| | |||
1 + 2 * 3 | |||
| | |||
1 + (2 * 3) | |||
| result equals 7, and not 9 (see also {{Wikipedia|Order of operations|PEMDAS}}) | |||
|- | |||
| | |||
[[sleep]] 10 + [[random]] 20 | |||
| | |||
([[sleep]] 10) + [[random]] 20 | |||
| {{Inline code|[[sleep]] 10}} will return [[Nothing]], then {{Inline code|+ [[random]] 20}} will be calculated but not used.<br> | |||
{{Inline code|[[sleep]] (10 + [[random]] 20)}} should be used instead | |||
|} | |||
</onlyinclude> | </onlyinclude> | ||
[[Category:Scripting Topics]] | [[Category:Scripting Topics]] |
Revision as of 18:54, 10 February 2021
Introduction
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 |
---|---|---|
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. |