Java Reference
In-Depth Information
statement;
...
[break;]
}
Incidentally...
The preceding example uses a non-existent computer language,
called pseudocode .Pseudocodeshowsthefundamentallogicofapro-
gramming construct, without complying with the formal require-
ments of any particular programming language. There are no strict
rules to pseudocode; the syntax is left to the programmer's imagina-
tion.TheprecedingpseudocodelistingcombineselementsoftheJava
language with symbols that are not part of Java. For example, the ...
characters (called ellipses) indicate that other program elements
could follow at this point. The bracket symbols are used to signal op-
tional components.
The controlling expression of a switch construct follows the switch
keyword and is enclosed in parentheses. The expression, usually a vari-
able, must evaluate to an integer type. It is possible to have a controlling
expression with more than one variable, one that contains literal values,
or to perform integer arithmetic within the controlling expression.
Each case statement marks a position in the code. If the case state-
ment is true, execution continues at the code that follows the case key-
word. The case keyword is followed by an integer or character constant,
or an expression that evaluates to an integer or character constant. The
case constant is enclosed in single quotation symbols (tic marks) if the
control statement is a char type. The following code fragment shows a
case construct in which the switch variable is of type char.
char charVar;
...
switch (charVar)
{
case 'A':
System.out.println(“Input was A”);
break;
case 'B':
System.out.println(“Input was B”);
break;
...
}
Search WWH ::




Custom Search