The switch statement is Java’s multiway branch statement. It provides an easy way to dispatch execution to different parts of the code based on the value of as expression. As such it often provides a better alternative than a large series of if-else-if statements. The value of the expression is compared with each of the literal values in the case statements. If a match is found the code sequence following that case statement is executed. If none of the constants matches the value of the expression, then the default statement is executed. The break statement is used inside the switch to terminate a statement sequence.
Friday, November 28, 2008
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment