switch (expression) { case value: instructions...  default: instructions... }

The switch statement allows for branching on multiple values of a variable or expression. The expression is evaluated and compared with the case values. If it matches any of the case values, the instructions following the colon are executed. The execution continues until either the closing bracket or a break statement is encountered. If the expression does not match any of the case statements, and if there is a default statement, the instructions following default: are executed, otherwise the switch statement ends.


int choice;
switch (choice)
case 0:
print("Zero! ");
case 1:
print("One! ");
case 2:
print("Two! "); break;
print("None of them! ");

See also:

if, while, goto, break, continue, comparisons ► latest version online