There's another control structure mph P which does something similar to if L. if and else
it's called a switch statement and it's used to compare a variable of value to many different values
and execute code based on that comparison.
For example let's conditionally execute some code based on the day of the week which is contained in
this variable then that starts our switch statement passing in this variable.
Then we add a series of case blocks with the value we want to compare the variable to in each block.
Let's add mun our Monday as the first one which is the work case followed by the value followed by a
colon and then the cold.
We want to execute.
Note that although we use curly braces for the whole switch statement we don't use curly braces for
the code blocks.
Inside each case.
Let's add another case far Tuesday and so far the rest of the days of the week.
With the day you variable set to queue for Tuesday let's see what happens when we run this cold.
We get Tuesday printed out but we also get the rest of the days of the week printed out too.
With a switch statements.
Once a case has matched the value it doesn't just execute the code for that case.
Rather it will continue down to the end of the switch statement.
You might actually want this behaviour which is why it does it like that.
But if you don't.
All we need to do is add a break command at the end of each block like this.
Now if we try running this code we get just Tuesday as we wanted.
There's one more thing we can add to a switch statement and that's the default block at the end.
This is equivalent to an else in an IF statement.
This code is executed if none of the case statements match the variable.
Let's change the variables value to something that doesn't match.
And then we try that in a browser.
We get the code from the default block.