zarqon
Well-known member
I have a question for our beloved mafia coders, which I am asking publicly because I believe the answer will be useful to all: how does mafia evaluate if statements with multiple conditions?
I searched as best I could and only found this hopeful but slightly mysterious allusion:
[quote author=Veracity link=topic=161.msg798#msg798 date=1147531250]
&& and || don't always evaluate the rhs, of course
[/quote]
Which inclines me to believe mafia first evaluates the left side of the && or || and if that expression evaluates as false, it does not attempt (or need) to evaluate the right side.
Which, happily, would mean situations like this are safe:
It would also mean that we can reduce chains of if statements:
to a single statement:
It appears from Veracity's admittedly dated quote that mafia works this way (left-first; if false, don't evaluate right). Is that a correct assumption?
(phrased as a "yes/no" question... I value your time.
)
I searched as best I could and only found this hopeful but slightly mysterious allusion:
[quote author=Veracity link=topic=161.msg798#msg798 date=1147531250]
&& and || don't always evaluate the rhs, of course
[/quote]
Which inclines me to believe mafia first evaluates the left side of the && or || and if that expression evaluates as false, it does not attempt (or need) to evaluate the right side.
Which, happily, would mean situations like this are safe:
Code:
string[string] somemap;
if (somemap contains "somevalue" && somemap["somevalue"] == "Yay!") {
...do stuff...
}
It would also mean that we can reduce chains of if statements:
Code:
if (condition1) {
if (condition2) {
if (condition3) {
...do stuff...
}
}
}
to a single statement:
Code:
if (condition1 && condition2 && condition3) {
...do stuff...
}
It appears from Veracity's admittedly dated quote that mafia works this way (left-first; if false, don't evaluate right). Is that a correct assumption?
(phrased as a "yes/no" question... I value your time.
