Boolean short circuiting

BlitzMax Forums/BlitzMax Programming/Boolean short circuiting

Ian C(Posted 2005) [#1]
Hello all

I was just messing about to test whether bmax short-circuits boolean expressions, and it seems that it does:



Does anyone know if this is intentional, and if so can I rely on it always being in the language, and on left to right ordering like C?

It's just that it's so damned handy!


Ian C


marksibly(Posted 2005) [#2]

Does anyone know if this is intentional, and if so can I rely on it always being in the language, and on left to right ordering like C?



Yes, it's intentional and yes, it will always evaluate left to right.


MrCredo(Posted 2005) [#3]
WOOOOOOOOOOOOOOOOW - i do not know this... i think this is the same how this works in C++...

test this in bb3d and bbmax. in bb3d this create a error - in blitzmax not!

nice

Type test
Field val:Int
EndType

Local xxx:test

If xxx<>Null And xxx.val=1 Then Print "COOL"
Print "OK"



taxlerendiosk(Posted 2005) [#4]
That's very useful. Also, you can just use "If xxx" instead of "If xxx<>Null" I think.


morszeck(Posted 2005) [#5]
that's old future.


Ian C(Posted 2005) [#6]
Fantastic news Mark! Cheers for that.

And MrCredo it is very powerful and just the same as C++ works (and C# for that matter)... Rather than having to nest lots of if's for cheap over expensive operations, just do:
if CheapCollisionCheck() and ExpensiveCollisionCheck() ...

And you've done a handy bit of opimisation as ExpensiveCollisionCheck() won't be called if CheapCollisionCheck() was false :-)


Ian C