Solved

switch statement

Posted on 2009-07-15
5
182 Views
Last Modified: 2013-12-17
Can I use different constant-statement in one single case?

for example:

switch (strCountry)

case "UNITED STATES" || "USA" || "US" ||   "MX" ||   "MEXICO" ||"MEX" ||"CANADA" || "CA":
{
do things...
}

case "SPAIN" || "FRANCE" || "GERMANY" :
{
do things...
}


obviously this doesnt work , but i was wondering if exists another way to do it because i have a lot of values for strCountry and i wanted to avoid  a lot of IF statements.
0
Comment
Question by:Veljean
[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
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 24862300
this should do:
switch (strCountry)
{
  case "UNITED STATES":
  case "USA": 
  case "US":
  case "MX":
  case "MEXICO":
  case "MEX":
  case "CANADA":
  case "CA":
    do things...
    break; 
  case "SPAIN":
  case "FRANCE":
  case "GERMANY" :
    do things...
    break;
}

Open in new window

0
 
LVL 22

Expert Comment

by:p_davis
ID: 24862316
you can just

case "US":
case "MX":

down untill you have all of your options then at then end put what you want to happen and the break;
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24862319
grrr
0
 
LVL 1

Author Comment

by:Veljean
ID: 24862334
thank you guys! but angelll was first :p
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24862340
angel is always first =)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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