Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

switch statement

Posted on 2009-07-15
5
Medium Priority
?
192 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 500 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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