Ramilol
Ramilol

Reputation: 3462

How can this switch statement be simplified?

I have two switch statement on inside another.
Like this

switch(something)
{
case h:
     switch(s)
     {
     case e:
     break;
     default:
     }
break;
default:
}

Can i simplify it any way? Is there a way to use only one switch statement?
I thought of moving it to a different function but I'll need to pass a lot of variables.

Upvotes: 0

Views: 289

Answers (5)

Mateen Ulhaq
Mateen Ulhaq

Reputation: 27271

Maybe this is what you want?:

if((something == h) && (s == e))
{
    // Do something
}

Upvotes: 0

Chris Pitman
Chris Pitman

Reputation: 13104

Without knowing what you are trying to accomplish with this logic we will not be able to siginificantly simplify this bit of code.

If the switch statements really are just checking for a single condition and then have default logic, this would probably be a little cleaner with if statements:

if (something == h)
{
     if (s == e)
    {

    }
    else
    {
        //default
    }
}
else
{
    //default
}

Upvotes: 0

flumpb
flumpb

Reputation: 1776

It depends on what 'something' and 's' are.

Also, based on this switch statement. You could remove it completely and get the same results.

Upvotes: 2

Tom Kilney
Tom Kilney

Reputation: 39

You could try indenting it more to make it more readable, but I don't see how you could do it with one switch

Upvotes: 0

chustar
chustar

Reputation: 12465

I don't think you need a break after the default, since there shouldn't be any skippable statements after it.

switch(something)
{
case h:
     switch(s)
     {
     case e:
     break;
     default:
     }
break;
default:
}

Upvotes: 0

Related Questions