switch case scope formatting

This is a code formatting question.

In writing switch statements I usually don't indent the case labels. Code like this looks nice and I'm happy:
1
2
3
4
5
6
7
8
9
switch (number)
{
case 1:
	// Do something.
	break;
case 2:
	// Do something else.
	break;
};


Sometimes I want to define variables inside the switch statement so I have to introduce a scope. It will look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
switch (number)
{
case 1:
{
	// Do something.
	break;
}
case 2:
{
	// Do something else.
	break;
}
};

It doesn't look very nice because the switch statement brackets are at the same level as the case brackets.

I guess I could do something like this instead:
1
2
3
4
5
6
7
8
9
10
11
12
13
switch (number)
{
case 1:
	{
		// Do something.
	}
	break;
case 2:
	{
		// Do something else.
	}
	break;
};

This will add a lot of indentation. I don't really like it. So how should I do it? How do you do it? Any thoughts?
I format it like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
switch (number)
{
    case 1:
    {
        //Do something.
        break;
    }	
    case 2:
    {
        //Do something else.
        break;
    }	
}
and i format it like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
switch (number)
{
case 1:
    {
        //Do something.
        break;
    }	
case 2:
    {
        //Do something else.
        break;
    }	
};
Last edited on
Topic archived. No new replies allowed.