Zebra0.com

cpp switchIntroduction to C++ Programming

Introduction to C++ Programming

Learn C++ 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 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.

  1. Calculate tip based on service: Y or N

  2. Print season from month

GlossaryGlossary for switch lesson
Full Glossary