Christopher said:
In a switch statement must a supply a default or what is the default by
default?
Is
switch(foo)
{
case 1:
return 1;
default:
break;
}
the same as
switch(foo)
{
case 1:
return 1;
}
Thanx,
Christopher
The first 'case' value which matches the 'argument'
to 'switch' causes that 'case clause' to be executed,
and continues linearly until a 'break' statement or
the closing brace is encountered. If none of the 'cases'
match and a 'default' case is defined, then that portion
is executed, also until a 'break' or the closing brace
is encountered. If none of the 'cases' match, and no
'default' case is defined, control flow passes to after
the closing brace.
Note that the 'default' case need not be listed last.
Some like to always use a 'default' case whether it
does anything or not, but you only really need it
if you actually want to execute some code in the
'default' case.
-Mike