Possible Duplicate:
break in a case with return.. and for default
If I have a switch statement:
switch()
{
case 1: ...
case 2: ...
...
default:
break;
}
Is there any reason for the break in the default clause? I see this in quite a few places, but isn't it unnecessary? What is the general practice?
Can another case label come after the default clause?
Putting the default clause between two case clauses If no match is found, execution will start from the default clause, and execute all statements after that. It also works when you put default before all other case clauses.
the default case in switch statement is not necessary,but it is useful when no case in switch is satisified or not matched then automatically it executes the default statement,if it is not there ,the switch statement is terminated.
The default statement is optional in type switch statement.
Switch cases should almost always have a default case. 2. To handle 'default' actions, where the cases are for special behavior.
Can another case label come after the default clause?
Yes, you are allowed to place the default clause anywhere within the switch block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With