Basicprogramming(.org) > General questions and discussions

Basic Logic

(1/4) > >>

B+:
Found at SdlBasic forum:

--- Quote ---'Hey, folks. While porting some code from Python, I accidentally discovered that sdlBasic accepts this syntax for comparison expressions:


'Code:
'dim x = 0
'print 1 <= x <= 10


'That shouldn't be valid Basic, and indeed it returns true when it's not supposed to, but sdlBasic compiles and runs the code. Beware!


--- End quote ---


--- Code: ---x = 0
PRINT "     1 <= x <= 10  is "; 1 <= x <= 10, " not supposed to return True???"
PRINT
PRINT "It is supposed to be True, Proof:"
PRINT "            1 <= x is "; 1 <= x '           > 0
PRINT "          0 <= 10  is "; 0 <= 10 '          > -1
PRINT "  ((1 < x) <= 10)  is "; ((1 < x) <= 10) '  > -1
PRINT
PRINT " See Basic knows the difference!"
PRINT "                 x is"; x '                 > 0
PRINT "1 <= x AND x <= 10 is"; 1 <= x AND x <= 10 '> 0

--- End code ---

ZXDunny:
Depends on the BASIC, I suppose.

Sinclair BASIC uses 0 = False, 1+ = True.

So the line 1<=x<=10 will always return true regardless of what x actually is - if 1<=x then we get 1 (true). If x=0 then we get false (0). 1 and 0 are less than 10, so it will always evaluate to true.

B+:
Oh yeah, SmallBASIC uses 1 for True too and it also returns True for

--- Code: ---PRINT "     1 <= x <= 10  is "; 1 <= x <= 10, " not supposed to return True???"

--- End code ---

Wether 1 <= x returns -1, 0, or 1 all those are less than 10. 

Is the Spell Checker working for you guys? it seems to have died for me on a couple of forums.

weather whether whatever what whaat whaaat :P

Aurel:
My main point about this is :

That shouldn't be valid Basic

and that is TRUE

n00b:
It actually is valid in pretty much every programming language.  Comparisons are still numerical operators and boolean is just a value that denotes 0 and NOT 0.

Navigation

[0] Message Index

[#] Next page

Go to full version