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:
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:
a == b != c // Is the same as… (a == b) != c
a != b == c // Is the same as… (a != b) == c
1 + 2 * 3 – 4 / 2 // Is the same as… 1 + (2 * 3) – (4 / 2)
false == 1 > 2 // This will fail to even compile, as it’s the same as… (false == 1) > 2
not 4 > 3 // This will also fail to compile, as it’s the same as… (not 4) > 3
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:
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 by Earth-Fury; 02-29-2008 at 02:29 PM.
Unprotecting maps is not right its like crime and YOU GO MAKE YOUR OWN MAP AND BE HAPPY! Don't be gay n00b!
1. You can if it is yours but you should not if it is not. It is like stealing information and using it as if it is your own. It si gay stuff and people who unprotect maps are gay themselves.
you have forgotten to write the t() and f() functions
Else, nice to know but i think for my mental sanity (to keep the code easily readable) i will still use () ^^
Last edited by Troll-Brain; 05-04-2008 at 06:13 PM.
Ands and Ors are short circuit, meaning in any circumstance where the answer is known after one of the two booleans is evaluated, they will immediately finish execution.
Ohhh, I gotcha, so if lets say it is an Or, and the first one is true, it will.... oh thats what the example means ><
So, if your second boolean function has some kind of unrelated call statement in there, you should be careful, because it will not always go through that secondary conditional function
__________________
Half of the worlds population is below average intelligence