How's working Conditional binary operator ?

BlitzMax Forums/BlitzMax Beginners Area/How's working Conditional binary operator ?

Armitage 1982(Posted 2009) [#1]
Hi

I often use Conditional AND operator and wondering how it's working.

For example take :
if A = true AND B = true AND C = true then ...

if A is false does BlitzMax will test the 2 others AND (I suppose)?

Also in a loop called very often Is it faster to write :
if A = true
  if B = true
    if C = true
      ...
    endif
  endif
endif


Or in a row like above ?

Thanks for any precisions ;)


plash(Posted 2009) [#2]
Yes, both forms work exactly the same.


Brucey(Posted 2009) [#3]
if A is false does BlitzMax will test the 2 others AND (I suppose)?

It shouldn't.
Well... if it is implemented well for efficiency, it shouldn't ;-)

You could always look at the generated asm and see what it does - if you can read it.


Warpy(Posted 2009) [#4]
No, it stops after the first false result:
Function odd(n)
	Print "is "+n+" odd?"
	If n Mod 2 Return True Else Return False
End Function

If odd(2) And odd(3) And odd(4)
	Print "wow!"
EndIf


After odd(2) is evaluated and returns False, it doesn't bother evaluating odd(3) or odd(4).


Who was John Galt?(Posted 2009) [#5]
function num(n)
    debuglog(n)
    return num
end function

if num(1)=9 and num(2)=2
    debuglog("duh")
endif


Try running something like that <untested>. From the debug you can work out if it's doing unecessary comparisons.


Who was John Galt?(Posted 2009) [#6]
Damn you Warpy! Beat me to it.


Armitage 1982(Posted 2009) [#7]
Thanks guys
Well documented and make sense :)