Not

BlitzMax Forums/BlitzMax Programming/Not

Jur(Posted 2009) [#1]
This command is begging to cause a bug in your code...

Strict

Local b=0

If Not b=4 Then Print "this is not printed"
If Not (b=4) Then Print "this is printed"


ziggy(Posted 2009) [#2]
The expression "Not 0" has a value of "-1", so as -1 is not equal to 4 there's no bug here.

"Not" has a higher operation order than a comparison (I *think* most unary operators have 'preference' over binary ones)


Amon(Posted 2009) [#3]
It would be better to use "<>".


Tommo(Posted 2009) [#4]
That's something you have to get used to.
I've been annoyed by this for times, but still havn't learnt my lesson. :)


Retimer(Posted 2009) [#5]
Yeah the only time I use not is for things like checking whether some is defined, or has a value at all.


GfK(Posted 2009) [#6]
Misuse of this command is begging to cause a bug in your code.


ImaginaryHuman(Posted 2009) [#7]
It makes sense to me.

When you put (b=4) in brackets, this is evaluated in a boolean kind of way, ie is b 4? no, =false, and then `not false` is the same thing as `is true`, thus it prints.

Just think what:

If Not ~(b=4) then Print "yes"


would do. :-D .... it won't print, since (b=4) is false, which has a value of 0, and then ~0 produces $FFFFFFFF, then Not will probably cause it not to print.