HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

keyword: and

12-17-2006, 06:30 PM#1
Themerion
I have a short question.

Let's say that I have an if-statement containing and. Will Warcraft stop evaluating the if-statement if it discovers that the first condition is false? Or will it in some cases save processing time to use nestled ifs rather than ands?

Collapse JASS:
// Will FunctionC be evaluated too?
if(false and FunctionC()) then
12-17-2006, 06:41 PM#2
Jacek
erm

if (3<2 and 3>4) will also work >_> AND is if two conditions are same, not if they are both true
12-17-2006, 06:48 PM#3
masda70
The following expression:
Collapse JASS:
(false and false)
doesn't return true.

I think he is asking something more like this:
Once the first operand of an AND operator expression is false, it stops evaluating the next operands included in that expression.

Collapse JASS:
function Test takes nothing returns boolean
 call BJDebugMsg("TEST!")
 return true
endfunction

function RunTest takes nothing returns nothing
if (false and Test()) then
endif
endfunction

'Test' is never evaluated, since after calling RunTest the "TEST!" message is never displayed.
12-17-2006, 06:59 PM#4
Themerion
Thanks masda70!
12-17-2006, 09:34 PM#5
blu_da_noob
This is a feature called Short Circuit Boolean Evaluation (or some such) and is useful when certain functions have major problems with incorrect input, eg:

if somestring != "" and HaveStoredInteger(cache,"lol",somestring) then //gamecache functions crash if they get an empty string