The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Boolean Expressions

Posted by Isa Leshko on July 16, 2000 at 11:42 AM

> Can anyone tell me---
> else if (inTokens.countTokens( )>= 4) -- Why does this work
> else if (inTokens.countTokens( )>= 4 && <=5) -- But not this??
> Alison Lukstin Australia

In Java, the logical and operator (&&) compares the values
of two boolean expressions. It requires two operands to its left and
right that must be legal boolean expressions.

<=5 is not a legal boolean expression. Like &&, <= is a binary
operator that requires a value to its left and a value to its right.
You cannot <= 5 is lacking a left-hand operand.

On the surface, it may seem convenient to implicitly
reference an operand from the previous boolean expression.
However, this practice could lead to code that is difficult
to read and interpret for both human eyes and for javac

Let's take your example:
inTokens.countTokens( )>= 4 && <=5

Should <= compare 4 or inTokens.countTokens() relative to 5?

For more details on complex boolean expressions, check out
a lecture I have written on the subject:

http://www.people.fas.harvard.edu/~ileshko/CSCIE-50a/notes/notes-complex-boolean-expressions.html

It is linked off the site I maintain for my students:
http://www.people.fas.harvard.edu/~ileshko/CSCIE-50a/

HTH,
Isa





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us