-1 should return false?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

-1 should return false?

Post by Joakim Christiansen »

Code: Select all

If -1
  Debug "Returned true"
EndIf
I think only that a value over 0 should return true, isn't this the case in most languages? Or am I just being silly now? What do you guys think?
I like logic, hence I dislike humans but love computers.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

No.
Only 0 (zero) returns False.
Any other values return true.

Code: Select all

x=1
y=0
z=-1

If x
   Debug "true"
Endif
If y
   Debug "true"
Endif
If z
   Debug "true"
Endif
You can imagine this behaviour better, if you imageine that an If-query looks like this:

Code: Select all

If x = anything
   Debug "true"
Endif
'anything' can be any value, except for 0.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

In fact, in many other languages -1 is used instead of 1 if a true boolean needs to be represented as an integer.
Post Reply