English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

You might need to provide a little more information before I could answer this to your satisfaction.

In theory, you would do something like this:

switch ($caseA)
{
case 1:
switch ($caseB)
{
case "a":
// do something
case "b":
// do something
}
case 2:
// do something
}

but nested switch statements aren't normally good programming practices. You should try to find another way to do it without nesting the switch.

2007-02-21 19:32:58 · answer #1 · answered by wa-webguy 3 · 0 1

By nesting it :-D

Example (in PHP, which is a C-like web-scripting language):

switch ($myvariable) //The original variable to test
{
case first:

//Stuff to do here....

break;

case second:

switch ($otherVariable)//The nested one...
{
case inside1:
//Stuff to do...
break;

case inside2:

//stuff to do...

}



break;

}

The only thing to watch for here is to make sure that you're putting all your brackets ( { } ) in the right place. That's going to be the most common error when you have a lot of nested statements like this. Just make sure to use clean code indenting, and you should be fine.

2007-02-22 03:37:40 · answer #2 · answered by poeticjustice72182 3 · 1 0

fedest.com, questions and answers