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 comparison table
Subject omit avoid by have syntax have example have purpose is a synonym of is a kind of
decision making statement    to make a decision on which branch of code to follow in a programconditional statementcontrol flow statement
switch-case statementthe keyword default and the default statements if they are not neededusing polymorphism
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;
}
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"
}
to execute one of a choice of statements depending on the value of a variablecase statementdecision making statement

Next decision making statementtry-catch-finally statement    Updecision making statement    Previous decision making statementif-else statement