Controlling the flow in your script is fine with if-else statements as long as there's not to many of them. When you have a lot of conditions it can be challenging to read, write and maintain a long list of if-else statements. When writing code with a lot of conditions it can be easier to handle them in a switch statement than in if-else statements.
​
The switch statement handles multiple conditions in an elegant way, but it is written in a different way than the if-else is done. First it takes in a parameter (value), then tries to find a match for it. If the switch statement finds a match, then runs the code belonging to the statement and then call break to jump out of the switch. If no match is found then it will go to the default statement. The default statement is optional, so if you don't provide a default statement and there is no match, the program will just jump out of the switch when done.
​
The way of writing a switch is a following:
Let's look at some code that looks a bit more real.
Here we use a parameter named color which will get a color as a value. If the value of color is blue or red then the variable message will get it's value accordingly to the case (blue or red). If color is not blue or red, then the default condition will be used.