You're right -- I should have looked it up! :-)
I stand corrected.
 
Cheers!
 
Greg
-----Original Message-----
From: Craig Dickson [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 26, 2002 2:44 PM
To: JDJList
Subject: [jdjlist] Re: In Java is this a valid expression (if( n <\<> 0 ) )

Actually the term "Exclusive OR" means something else (I have never heard the term "Inclusive OR" used).
 
The fact that Java only evaluates the right hand side operand of the Conditional-Or operator if it is necessary to determine the outcome is colloquially called "lazy evaluation" I believe. See section 15.23 of the JLS for further details.
 
The exclusive-or operator is actually ^ (hat). It only evaluates to true if both operands are different (ie. one true and one false). If both operands are the same (ie. both true or both false) then it evaluates to false. See section 15.22.2 of JLS on this one.
 
Cheers,
Craig
-----Original Message-----
From: Greg Nudelman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 26, 2002 2:27 PM
To: JDJList
Subject: [jdjlist] Re: In Java is this a valid expression (if( n <\<> 0 ) )

May the problem be the Java's nature of the "OR" || which is "Exclusive OR", i.e.

a || b

means that if a is true, b is not evaluated.  Maybe you're looking for "Inclusive OR" i.e. if a or b, both getting evaluated, which in Java is:

a | b

Although, frankly, I do not see much of a point for this here...

IMHO,

if( n <\<> 0)

=>

if(n < 0)

in Java will cover both conditions, as the number n can not be sulmonteniously less then 0 and equals to 0.

Yah? Or am I missing something?

Greg


-----Original Message-----
From: Spencer W. Thomas [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 26, 2002 2:13 PM
To: JDJList
Subject: [jdjlist] Re: In Java is this a valid expression (if( n <\<> 0
))


Arrgh.  I meant to say "whenever n is NOT 0".

Spencer W. Thomas wrote:

>
>
> [EMAIL PROTECTED] wrote:
>
>> No. I'm assuming you are trying to say "if (n is less than or not
>> equal to 0)...."
>> You can try this instead:
>>
>>   int n={some integer};
>>
>>   if (n < 0  ||  n != 0)
>>     System.out.println("foo happens here");
>>   else
>>     System.out.println("bar happens here");
>
>
> Try this.  It will print "foo happens here" only when n is 0.
>
>>
>>
>> However, a clearer way to code it is this:
>>
>>   if (n >= 0)
>>     System.out.println("bar happens here");
>>   else
>>     System.out.println("foo happens here");
>> ____________________________________________________
>
>
>
>
> ____________________________________________________
> To change your JDJList options, please visit:
> http://www.sys-con.com/java/list.cfm
>
> Be respectful! Clean up your posts before replying
> ____________________________________________________



____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to