Sometimes, it may happen that the value passed to a switch statement block does not match any of the foreseen cases. Which case of the switch is going to be executed? None? The first one?
- 22 Mar 2019
Then, the default case is executed when the data evaluated by the switch block does not match any of the cases. The default case is one of all given cases and is marked with a dot:
You can change the default case by just selecting any other case as shown:
NOTE: if you delete the defaut case, the first case will become default:
A good practice is to have a case with a value that can not be met, usually -1. That case is set to default and covers any errors and unexpected data. Within the case you can put a sound block with "Error" or some other notification for the occured error.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons