switch Statement

In this lesson, an introduction of the switch statement, its basic syntax, and how it is written using an example is provided.

We'll cover the following

The switch case construct

This switch clause tests an input variable for equality with any number of cases and then executes the corresponding code.

The switch statement is very similar to the if-else if statement. The only difference is that the switch case construct only uses int, short values, and character constants or character literals. For this reason, the switch-case can come in handy, ​but it is limited to these circumstances.

Get hands-on with 1400+ tech skills courses.