The Artima Developer Community
Sponsored Link

Java Answers Forum
What the command for OR ... ?

6 replies on 1 page. Most recent reply: May 3, 2003 12:40 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Kris K

Posts: 6
Nickname: krisk
Registered: Apr, 2003

What the command for OR ... ? Posted: May 1, 2003 9:11 PM
Reply to this message Reply
Advertisement
I want to do something like

if ((x>=1 && x<=10) OR (x>=21 && x<=30))
{
//perform a command
}


I am not sure if it will work, I made this up as an example. Though will this format work, and also what is the command in place of OR. I tried || and it doesn't work.


Rahul

Posts: 52
Nickname: wildhorse
Registered: Oct, 2002

Re: What the command for OR ... ? Posted: May 1, 2003 11:09 PM
Reply to this message Reply
For OR operation use || i.e. two pipe symbols.

Kris K

Posts: 6
Nickname: krisk
Registered: Apr, 2003

Re: What the command for OR ... ? Posted: May 2, 2003 3:34 AM
Reply to this message Reply
I am getting two errors with my code, please advise.

int value1 = (int)(input1.charAt(count));
if ((value1>=65 && value1<=78) || (value1>=97 && value<=110))
{
char current1 = (char)(13+....
}

anyway, why wont this if statement compile?

also,
just a quick one, if i wanted to check >=79 && <=90 or >=111 && <=122. do i use

elseif(.....)
{
....
}
or

else(....)
{
....
}

Rahul

Posts: 52
Nickname: wildhorse
Registered: Oct, 2002

Re: What the command for OR ... ? Posted: May 2, 2003 4:12 AM
Reply to this message Reply
if ((value1>=65 && value1<=78) || (value1>=97 && value<=110))
{
char current1 = (char)(13+....
}

You may be getting an error in the 'if' statement above as you might not have declared 'value' ...(value<=110)
Next, you should have specified your statement with brackets. That makes it easier to understand which conditions are AND-ED or OR-ED.
I have assumed that you want that you want to find 'check' thats either between (79 and 90) or (111 and 122).

if ((check >=79 && check<=90)||(check>=111 || check <=122)){
}


else if () is used normally if you yet have some condition to check after the previous one fails.

else() may be used when all conditions have failed, similar to default in switch..case statements.

Kris K

Posts: 6
Nickname: krisk
Registered: Apr, 2003

Re: What the command for OR ... ? Posted: May 2, 2003 3:05 PM
Reply to this message Reply
if ((check >=79 && check<=90)||(check>=111 || check <=122)){
}



is there supposed to be 2 ||'s in the statment

i was checking, between if((w and x) || (y and z))
i dont have time now, ill check if i can get it to work later.

Duane

Posts: 5
Nickname: duane
Registered: Mar, 2003

Re: What the command for OR ... ? Posted: May 3, 2003 10:25 AM
Reply to this message Reply
try writting it like this

if ((x>=1 && x<=10) || (x>=21 && x<=30))

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: What the command for OR ... ? Posted: May 3, 2003 12:40 PM
Reply to this message Reply
Looks like a typo to me in:
if ((value1>=65 && value1<=78) || (value1>=97 && value<=110))

Maybe should be:
if ((value1>=65 && value1<=78) || (value1>=97 && value1<=110))

Second question

The second expression:
>=79 && <=90 or >=111 && <=122
would only be evaluated when you use it in an else if clause
if the first if statment is false

By the choices of your upper and lower limits in the first if clause, they exclude each other logically

so it would not matter whether you used else if or an else clause.

Two separate if clauses would work also.

Flat View: This topic has 6 replies on 1 page
Topic: >> operator and 0xff Previous Topic   Next Topic Topic: EJb questions

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use