switch Statements
In this lesson, we will learn all about switch statements, their use, and syntax.
We'll cover the following
What are switch
statements?
A switch
statement is a unique conditional statement that allows a variable to be tested for equality against a list of values. Each value is called a case
.
The variable is checked for each case.
switch
Statements basically provide decision making capability: choose an option corresponding to the expression. The options are chosen based on two criteria of the options:
-
Based on Index – Choose the option whose index corresponds to the value of the expression.
-
Based on Matching Value - Choose the option which is an exact match of the expression.
The code flow of switch statement can be represented using the following illustration.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy