--- In [email protected], John Gaughan <[EMAIL PROTECTED]> wrote:
>
> John Matthews wrote:
> > --- In [email protected], John Gaughan <john@> wrote:
> >
> >> You can also separate the declaration and assignment of the
variable.
> >> For example, declare the variable outside that scope in a place
such as
> >> the start of the method or block, and assign it inside the case.
> >>
> >
> > I could, but the variable is only used inside the case, so it makes
> > sense to keep its scope to within the case only.
>
> Is the scope not the switch, rather than the case? I thought cases were
> just labels, and the switch was the scope.
That's why you add the braces after the case, to restrict the scope eg.
case X:
{
int i;
:
break;
}
But you could argue that if the code inside the case is complex enough
to warrant its own variables then it ought to be made into a separate
function. However readability can be improved by keeping code together.