Page 1 of 1 1
Topic Options
#29067 - 2002-09-15 03:37 PM NOT vs Greater-Than/Less-Than
mjoni Offline
Fresh Scripter

Registered: 2002-05-11
Posts: 13
What is the difference between "NOT" and "<>" are they basically the same thing? I don't understand when it would be appropriate to use one over the other...

If @ERROR <> 0...

If @ERROR NOT 0...

Any thoughts?

Top
#29068 - 2002-09-15 03:41 PM Re: NOT vs Greater-Than/Less-Than
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
in your example, there is no difference.

anyway, not is easier to understand.
just like "and" is used instead of "&"
or "or" instead of "|"

also, to create boolean values with kixtart, you can do it:
$false = not 1
$true = not $false
_________________________
!

download KiXnet

Top
#29069 - 2002-09-15 03:47 PM Re: NOT vs Greater-Than/Less-Than
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Give this a try:
code:
? (NOT 5)
? (4 <> 5)
? (5 NOT 6)

NOT is a UNARY operator for logical operations wiht one operand. '<>' is a BINARY operator for mathematical operations resulting in a LOGICAL TRUE or FALSE.
NOT 0 is '1' or TRUE and 'NOT x' with X<>0 is '0' or FALSE.

The last code line will fail because NOT is an UNARY operator, thus the '5' is incorrect.

So, that means that '@ERROR NOT 0' is syntactically incorrect. It would also be sufficient to just do 'IF @ERROR' to catch an existing error code or 'IF NOT @ERROR' to catch an error code of '0'.

[ 15. September 2002, 15:50: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#29070 - 2002-09-15 04:07 PM Re: NOT vs Greater-Than/Less-Than
mjoni Offline
Fresh Scripter

Registered: 2002-05-11
Posts: 13
I kind of get it- but I don't understand how you would use NOT.

If NOT 5

is the correct syntax, but if What is not 5? By itself it doesn't seem to be of any use.

If $X NOT 5

seems logically correct, but like you say is bad syntax. I cannot find any script examples that use NOT. Have you ever used it in a real script?

Top
#29071 - 2002-09-15 04:16 PM Re: NOT vs Greater-Than/Less-Than
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
just like jens already said:
If @ERROR <> 0 "error" endif
is same as:
If @ERROR "error" endif

and:
If @ERROR = 0 "no error" endif
is same as:
If not @ERROR "no error" endif

lets say, you have var in script which normally has some length string in it.
if it sometimes gets to zero length, you could test it:
if 0=len($string)

or with not:
if not $string
_________________________
!

download KiXnet

Top
#29072 - 2002-09-15 04:20 PM Re: NOT vs Greater-Than/Less-Than
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
As I said, NOT is a UNARY operator, thus it is NOT x because it takes only ONE operand. If you want to find out whether a variable x is not equal to 5, then you will have to use the mathematical operation 'x<>5' and not the logical operation 'x NOT 5' because the NOT is used incorrectly (and it is actually logically incorrect [here I'm not talking about brain logic but math logic]).

It's partly a matter of semantics and correct expression of the underlying mathermatical and/or logical structure.

[ 15. September 2002, 16:21: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#29073 - 2002-09-15 04:38 PM Re: NOT vs Greater-Than/Less-Than
mjoni Offline
Fresh Scripter

Registered: 2002-05-11
Posts: 13
So if $X has any value then

NOT $X = 0

If $X is not null (has any value at all)

NOT $X = 1

I've got it!?!

Top
#29074 - 2002-09-15 04:44 PM Re: NOT vs Greater-Than/Less-Than
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Nope. Here's the look-up table for NOT:
code:
NOT 0 | NOT 1 | NOT x (with X>0)
--------------------------------
1 | 0 | 0

Remember, this is a logical operation with only two valid results, '0' or FALSE, and '1' or TRUE. Also, NULL and the number '0' are not really the same, NULL is more like 'nothing'.
_________________________
There are two types of vessels, submarines and targets.

Top
#29075 - 2002-09-15 05:02 PM Re: NOT vs Greater-Than/Less-Than
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
might even say, bitwise.
if you ever play with boolean values, you will see operands like:
not, and, or [xor, xnor, nand]

anyway, if you don't see where you would use that, do you need it then? [Wink]

what comes to the resulting value,
having anything in the var, results with not nothing.
if the value in the var is 0, output is true (1)

it's easier to demonstrate, so try this:
code:
$x=5
? not $x
$x="a"
? not $x

$x=0
? not $x
$x=""
? not $x

you will see, first 2 have zero (false) value output and last ones come with 1 (true) output.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 735 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.056 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org