Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

verfiy if else statement

Posted on 2006-07-06
3
Medium Priority
?
246 Views
Last Modified: 2010-04-01
folks

I have the following:

if (mroApp.equals("WOTRACK"))
            {
                  
                  mroRepName = "woprint";
            }
but i want to add a statement into this:

if (mroApp.equals("WOTRACK"))
            and (mroSite.equals("JFK"))

   mroRepName = "woprint2";

so its an if esle

could anyone advise what the correct way

the pschuedo code is

if app =wotrack then repname=woprint else if app =wotrack and site=jfk then woprint2

all other will not have the site parameter bound

all help will do

rutger

0
Comment
Question by:rutgermons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Expert Comment

by:evnafets
ID: 17055800
The logic you specified is bad, because the second condition is a subset of the first.
If the second condition is true, the first condition is also true, and so fires first - you would never get into the second test.
Reversing the tests, putting the more specific one first would work.

I would probably write it like this.

  if ("WOTRACK".equals(mroApp)){
    mroRepName = "JFK".equals(mroSite) ? "woprint2" : "woprint";
  }

Using "WOTRACK".equals(mroApp) rather than mroApp.equals("WOTRACK") makes the code more robust by avoiding a null pointer exception if mroApp is null.
I also used a ternary statement to set the value of the mroRepName variable.

0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 17055965
if (mroApp.equals("WOTRACK")
         && (mroSite.equals("JFK"))
   mroRepName = "woprint2";

I think this is what u wanted.
0
 
LVL 8

Accepted Solution

by:
kaliyugkaarjun earned 2000 total points
ID: 17056345
If (mroApp.equals("WOTRACK"))
{
   if(mroSite.equals("JFK"))
       mroRepName = "woprint";
   else
        mroRepName = "woprint2";
}
   
   
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whoever said that “a picture is worth one thousand words” observed a fact that can dramatically affect your marketing success. Most people tend to learn visually, so many publishers commonly acknowledge the effectiveness of visual learning by using…
In this article, WatchGuard's Director of Security Strategy and Research Teri Radichel, takes a look at insider threats, the risk they can pose to your organization, and the best ways to defend against them.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question