Java
Learn Java in step-by-step lessons.
switch: looking at one variable
The switch construct offers an alternative to nested if statements. Switch can be used when the test invloves a single variable with a small number of possible values.
The syntax is:
switch(variable) {
case value: statement; statement; statement; break;
case value: statement; statement; break;
case value: statement; break;
default: statement;
}
When a match is found, every statement is executed until there is a break.
Please study the material at each of the links below.
- Print season from month
Glossary for switch lessonFull Glossary