IF and !

May 20, 2008
12,167
133
Syracuse, NY, USA
I'm just curious about the peculiar behavior of the exclamation point.

Code:
v:\> if ! == 1 (echo yes) else (echo no)
yes

v:\> if ! EQ 1 (echo yes) else (echo no)
Usage : IF [/I] [NOT] condition [.AND. | .OR. | .XOR. [NOT] condition ...] command

v:\> if 1 == ! (echo yes) else (echo no)
no

v:\> if 1 EQ ! (echo yes) else (echo no)
no
 

rconn

Administrator
Staff member
May 14, 2008
12,556
167
I'm just curious about the peculiar behavior of the exclamation point.

Code:
v:\> if ! == 1 (echo yes) else (echo no)
yes

v:\> if ! EQ 1 (echo yes) else (echo no)
Usage : IF [/I] [NOT] condition [.AND. | .OR. | .XOR. [NOT] condition ...] command

v:\> if 1 == ! (echo yes) else (echo no)
no

v:\> if 1 EQ ! (echo yes) else (echo no)
no

I'm a bit baffled as to your intentions, but the result is WAD.

The syntax:

if ! == 1 (echo yes) else (echo no)

equates to "compare an empty string to the string "1", and then invert the result". Putting the NOT test ("!") on the (wrong) side of the comparison results in a string test comparing "1" to "!".