Skip to content

Challenge Adding A Default Option In Switch Statements

Quincy Larson edited this page Aug 20, 2016 · 1 revision

Challenge Adding a default option in Switch statements

In a switch statement you may not be able to specify all possible values as case statements. Instead, you can add the default statement which will be executed if no matching case statements are found. Think of it like the final else statement in an if/else chain.

A default statement should be the last case.

switch (num) {
  case value1:
    statement1
    break;
  case value2:
    statement2;
    break;
...
  default:
    defaultStatement;
}
Clone this wiki locally