Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

General practice to specify a break after a default clause? [duplicate]

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?

like image 269
Nathan Osman Avatar asked Jun 09 '10 05:06

Nathan Osman


People also ask

Can we write default before case?

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.

Does a switch have to have a default?

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.

Is default required in switch Golang?

The default statement is optional in type switch statement.

Is default necessary in switch case PHP?

Switch cases should almost always have a default case. 2. To handle 'default' actions, where the cases are for special behavior.


1 Answers

Can another case label come after the default clause?

Yes, you are allowed to place the default clause anywhere within the switch block.

like image 165
R Samuel Klatchko Avatar answered Oct 13 '22 00:10

R Samuel Klatchko