- Joined
- Feb 18, 2004
- Messages
- 394
Precedence in JASS
The rules of precedence are important if you don’t want your code littered with needless parenthesis. JASS has only a few operators, so remembering their precedence is not so hard:
The higher on the list, the higher an operators precedence. If two operators are in the same row, they share the same precedence and are thus executed from left-to-right. By this chart, the following examples are all true:
The
Much credit to PurplePoot for helping me test precedence
Edit: Tiny formatting edit and removal of signature
Definition of PrecedenceIn a programming language, the precedence of an operator determines in what order it will be evaluated. An operator with a higher precedence will be evaluated before another with a lower precedence. For instance multiplication has a higher precedence than addition.
http://www.google.ca/search?q=define:+precedence
( ) |
not |
* / |
+ - |
<= >= > < == != |
and or |
The higher on the list, the higher an operators precedence. If two operators are in the same row, they share the same precedence and are thus executed from left-to-right. By this chart, the following examples are all true:
JASS:
a == b != c // Is the same as…
(a == b) != c
JASS:
a != b == c // Is the same as…
(a != b) == c
JASS:
1 + 2 * 3 – 4 / 2 // Is the same as…
1 + (2 * 3) – (4 / 2)
JASS:
false == 1 > 2 // This will fail to even compile, as it’s the same as…
(false == 1) > 2
JASS:
not 4 > 3 // This will also fail to compile, as it’s the same as…
(not 4) > 3
JASS:
a == b or c == d // Is the same as…
(a == b) or (c == d)
The
or
and the and
operators are executed in a short circuit manner. This means that if from the current execution, an answer is determinate, execution stops. By this, the following are both true:
JASS:
f() // Returns false
t() // Returns true
t() or f() // f() will never be executed.
f() and t() // t() will never be executed.
Much credit to PurplePoot for helping me test precedence
Edit: Tiny formatting edit and removal of signature
Last edited: