Solved

switch statement

Posted on 2009-07-15
5
181 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
  • 3
5 Comments
 
LVL 142

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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