Solved

switch statement

Posted on 2009-07-15
5
179 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular JS Route 3 54
Not showing JavaScript in the list 5 39
Javascript and Jquery not firing 9 42
.NET tools for adding thread safety to a web app? 3 16
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now