The switch-case Construct

This lesson discusses the switch-case construct in detail.

Introduction

In the last two lessons, we studied the if-else construct. There is another control structure known as the switch-case structure.

The keyword switch is used instead of long if statements that compare a variable to different values. The switch statement is a multiway branch statement that provides an easy way to transfer flow of execution to different parts of code based on the value. The following figure explains the basic structure of the switch-case construct.

Get hands-on with 1400+ tech skills courses.