Programming Basics #19 Switch Statement
Programming Course. The Basics of Programming.
#19 Switch Statement

Learn to code.

Using the switch statement

You will end up writing if statements in pretty much every program you ever write.

But it’s not the only option for checking a condition.

Let’s say you checking a variable for a very specific values.

I create a variable which called grade.
And in some where in the program, i want to check if it is, regular, or is it premium, or is it diesel.

We have very specific values that we are asking for.

We can do this has a serials of sepaerated self contained if statements, Like i have here.

Or we can use it with the else condition, combined all together.
But this can get a little clunky, particularly if don’t have 3 or 4 but if you have 10 or twelve.

So, in this kind of situation, java_script and the most programming languages, have something called the switch Statement, instead the If Statement.

In some other languages is called the select, or the select case statement. Is the ability
to list, in one place, several situations or cases, that you’r looking for in a very readable format.