How's working Conditional binary operator ?
BlitzMax Forums/BlitzMax Beginners Area/How's working Conditional binary operator ?
| ||
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 ;) |
| ||
Yes, both forms work exactly the same. |
| ||
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. |
| ||
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). |
| ||
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. |
| ||
Damn you Warpy! Beat me to it. |
| ||
Thanks guys Well documented and make sense :) |