Java   View all facts   Glossary   Help
syntactic unit > statement > control flow statement > decision making statement > switch-case statement
Next decision making statementtry-catch-finally statement    Updecision making statement    Previous decision making statementif-else statement   

switch-case statement
(case statement)
subjectfact 
switch-case statementis a synonym of case statement2001-10-19 11:36:16.0
can be avoided by using polymorphism    source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:38:02.0
can omit the keyword default and the default statements if they are not neededadded by: JK, source: On To Java, 2001-10-19 11:38:02.0
has example
int month;
switch (month) {
case 1: System.out.println("January"); break;
case 2: System.out.println("February"); break;
case 3: System.out.println("March"); break;
default: System.out.println("Not January, February or March"
}
added by: JK, source: Sun Java Tutorial, 2001-10-19 11:38:02.0
has purpose to execute one of a choice of statements depending on the value of a variableadded by: JK, 2001-10-19 11:38:02.0
has syntax
switch(integer producing expression)
{
case integer constant 1:
// statements to execute for integer 1
break;
case integer constant 2:
// statements to execute for integer 2
break;
...
default:
// statements to execute if none of the above is true
break;
}
added by: JK, source: On To Java, 2001-10-19 11:38:02.0
is a subtopic of Loops and Decision Making2001-10-19 11:38:02.0
is a kind of decision making statementadded by: JK, source: Sun Java Tutorial, 2001-10-19 11:38:03.0
is a kind of decision making statementsource: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:38:03.0
statementis terminated by a semicolon    2001-10-19 11:37:57.0
should be not more than one line long if possible2001-10-19 11:37:57.0
syntactic unithas syntax rule
bold = mandatory
italic = non-terminal
normal font = optional
2001-10-19 11:38:04.0