Jump to content

Help With Simple Java "if" Syntax


kirky_D

Recommended Posts

Ok, so i'm a bit of a beginner at java, i've searched google to no aveil.

 

Is there a way to have more than one statement in an 'if' operation?

 

e.g.

(english worded)

if a = b AND c = d then

 

I have found out how to use the 'or' bit in an if statement by using '|' but i cant manage AND, can anybody help me?

Share this post


Link to post
Share on other sites

'|' is to OR as '&' is to AND.

 

& is the symbol you want to use for logical AND statements

 

Just a note.... & is different than && (same with | and ||). One is a bitwise operator and the other is a logical operator. In most cases if you are using AND in a if statement to test if two conditions are both true you want to use && not &.

 

Here is a link about it.

Share this post


Link to post
Share on other sites

java is very similar to c/c++... the equality is the same as well, so conditional equality testing is ==, assignment is =

 

if(a==b && c==d)
{
// do some stuff if the conditions were met
e = 7; // sets the value of e to 7
}
else
{
// do some stuff if the conditions were not met
} //endif

Edited by hardnrg

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...