switch
Statement (Cont.)
Expression can be of type byte , short , int , char , String , or an enumeration.
Dulplicate case values are not allowed.
The default statement is optional.
The break statement is used inside the switch to terminate a statement sequence and is optional.
If omitted, execution will continue on into the next case.
|
break
Keyword
break
keyword, it breaks out of the switch block.
This will stop the execution of more code and case testing inside the block.
When a match is found, and the job is done, it is time for a break.
There is no need for more testing.
A break can save a lot of execution time because it “ignores” the execution of all the rest of the code in the switch block.
default
Keyword
default
keyword specifies some code to run if there is no case match.
Note that if the default statement is used as the last statement in a switch block, it does not need a break.
I took the shell off my racing snail, thinking it would make him run faster. If anything, it made him more sluggish. |