File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AND / OR Statements

 
LaTeef Lusk
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to do multiple AND/OR statements in an if statement. I am trying to see if parenthesis need to be around each individual AND/OR statement or can I just have one parenthesis around the entire if statement?
 
Eric Daly
Ranch Hand
Posts: 143
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on what you're trying to do. You need to put parenthesis around statements you want to be evaluated first, but it is possible to chain a bunch of AND/OR statements together. Just make sure you know exactly what you're doing (what order things will be evaluated in). You might be better off with nested if statements or maybe a switch statement.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Find an operator precedence chart for Java and it will tell you all that you need to know.
 
Derek Szpik
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
most often, you can just do if(i<=MAX_SIZE&&i>=MIN_SIZE){...}, but as mentioned it does depend on what you're doing. Try posting a code segment, or finding the chart that Bear mentioned, and your problems should be solved quickly.
 
Juan Sifuentes
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use parenthesis to "group" things together so they wont mix variables with both AND/OR

example:
if ( (1 and 2) or ( 3 and 4 ) ) vs. if ( 1 and 2 or 3 and 4 )
if ( (1 or 2) and ( 3 or 4 ) ) vs. if ( 1 or 2 and 3 or 4 )

if you don't use too many parenthesis, it will make your statement easier to read and also make it a more secure from running the statement wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic