Course Content
Introduction to C++
Introduction to C++
1. Basics
The Keyword Default
To specify the code to execute if there is no case match, you can use default
keyword in switch statement. For example, the coffee machine has a list of types of coffee by its number (from 1 to 3). If you want to choose one, just type its number. But there is a huge amount of numbers that users can type by mistake. Here we can use the default
keyword:
The default
statement executes the code when the non of statements are true.
The
default
statement must be at the end of the switch.
Everything was clear?
Thanks for your feedback!
Section 3. Chapter 9