Learn C++ in step-by-step lessons.

The switch construct offers an alternative to nested if statements. Switch can be used when the test involves 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.
- Calculate tip based on service: Y or N
- Print season from month
Glossary for switch lesson
Full Glossary