case keyword

Syntax

>>-case-ConstantExpression-:-><

Description
The case keyword labels a block of code to execute if the ConstantExpression matches the Expression of the enclosing switch statement.  If there is no break statement before the next case statement, execution "falls through" into the next case.

The following must be true or a compilation error occurs:

Examples
The following example illustrates how the switch statement determines at which case label execution should start, and how execution can fall through into another case.

final int CASE_1 = 10;          // the case constants are int's...
final int CASE_2 = 20;

int theSwitchExpression = 20;   // and so is theSwitchExpression

switch (theSwitchExpression) {
case CASE_1:
            // do something interesting
            // we won't execute this case since CASE_1 != theSwitchExpression
            // fall through to the next case
case CASE_2:
            // this is the case we will execute
    break;  // not necessary, but it is good form
}

ngrelr.gif (548 bytes)
Syntax diagrams
Java types
break keyword
byte keyword
char keyword
int keyword
short keyword
switch keyword

Source: The Java Language Specification. Copyright (C) 1996 Sun Microsystems, Inc.