Skip to content

Latest commit

 

History

History
19 lines (16 loc) · 529 Bytes

Challenge-Adding-A-Default-Option-In-Switch-Statements.md

File metadata and controls

19 lines (16 loc) · 529 Bytes

#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;
}