How do ifs work in bmax ?

BlitzMax Forums/BlitzMax Programming/How do ifs work in bmax ?

skn3(Posted 2004) [#1]
a = 100
b = 50
c = 31
d = 5
if a = 100 and b < 10 and c > 30 and d <> 4
end if


Will bmax test the entire line or break when one of the conditions isn't met ?


marksibly(Posted 2004) [#2]
And and Or are 'shortcircuit' - they will 'break' as soon as the condition is known.

This isn't documented, is it...oops.


skn3(Posted 2004) [#3]
AWSOME this was high up on my wishlist. Now I can create a lonnnnnngggg if statement without having to worry about splitting it onto seperate lines.

Thanks :D


Jeroen(Posted 2004) [#4]
I always put ( and ) to see what's really going on, and which parts have priority over others.


Warren(Posted 2004) [#5]
And and Or are 'shortcircuit' - they will 'break' as soon as the condition is known.

-Awesome-, Mark, thanks! I've wanted this for so long now.

That kicks ass!


ImaginaryHuman(Posted 2004) [#6]
It makes ordinary sense if you think about it. An AND operation requires that all of the included parts produce a `true` result, so if ANY of them are false there is no point carrying on, unless you also mix in an OR ??


Dreamora(Posted 2004) [#7]
Make no sense to check the whole function didn't prevent that a lot of languages check whole boolean functions *ggg*

if you have this for example

if a > 0 and image.frame[0] <> null then

with a image that does not exist ( null ) they will run into bad probs or make the programmers life far harder than needed as you will need to split up the ifs.

Quite happy to hear that it is shortcircuit
thanks Mark :)


Warren(Posted 2004) [#8]
It makes ordinary sense if you think about it. An AND operation requires that all of the included parts produce a `true` result, so if ANY of them are false there is no point carrying on, unless you also mix in an OR ??

Correct. But previous Blitz languages didn't do that ... they evaluated the entire if statement, every time.


ImaginaryHuman(Posted 2004) [#9]
Oh I see, well there you go then :-)


Hotcakes(Posted 2004) [#10]
But And and Or don't do the same thing as & and | (which is what And and Or used to be in Blitz) - which I still don't understand =]


LarsG(Posted 2004) [#11]
AND + OR are logical, which mean they return either true of false. Like:
if (1 = 1) AND (2 = 2)

it will return true.

on the other hand, & + | are bitwise operators, which mean they will change the two given numbers, and result in a different number.
(wow, the pipe symbol was hard to find on the mac.. :p)
ie.
    01100110
  & 11001011, will give:
    --------
    01000010
    ========

and..
    01100110
  | 11001011, will give:
    --------
    11101111
    ========



Hotcakes(Posted 2004) [#12]
OK that I understand. And I should probably leave it at that, but I'm not going to. =]

Somewhere else somebody posted the differing results for And and &, and And doesn't really return true (as in 1 or -1), it still returns some weird garble of bits. I was wondering if there is any method to that or if it should really only be reliably used as a way to return close-to-true for if statements (since anything not 0 for an if statement is considered a 'yes')...