Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch / case question

Status
Not open for further replies.

mgw4jc

IS-IT--Management
Feb 14, 2001
10
US
Is it possible for one case to handle multiple values? For example, I have to run the same code for two of the several case options. Can you do something like case "value1" || "value2"?
 
Kind of... Do it like this
[tt]switch (expression)
{
case "value1":
case "value2":
//Code goes here
break;
case "value3":
//....
}[/tt]
The program will run starting from the matching case to the break statment. If you leave out the break statment for value1 it will just continue down to value2.
 
I suppose I should have known that as I have accidentally left out breaks before and had all kinds of code executing.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top