The switch statement is a multiway branch statement. The general form of the switch statement is given below:
case value1://statements
break;
case value2://statements
break;
.
.
default:
//default statements
}
The expression must be of int, char, byte, or short data type and the data type of the values specified must be compatible with the expression.
Each case value must be a unique literal value. Variables are not allowed as case values.
The execution process of a switch statement is as follows:
The value of the expression is matched with each of the literal values in the case statements. If a match is found then the code sequence following that case statement is executed. If none of the values match, then the default statement is executed.
If the default statement is not given and no matching value is found, then no further action is taken.
- Download free practice test for master-ciw-enterprise-developer Master CIW Enterprise Developer exam.
- Get certified in first attempt download scbcd - SCBCD simulation.
- Download practice question and study guide for scdjws for exam.
- Pass SCJA in first attampt.
- Pass SCJP in first attampt.
- Download free practice test for SUN SCJP 5/6 exam.
- Download free practice test for scmad SCMAD exam.
- Get certified in first attempt download scwcd - SCWCD simulation.
- Pass SCJA in first attampt.
- Get certified in first attempt download CX310-055 - Java 5.0 simulation.
- Download practice question and study guide for CX310-065 for exam.
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.
