Switch Statements to the Rescue!

Objective: Creating and implementing a Switch Statement.

Switch Statements act like streamline conditionals. They are useful for when you want to compare a single variable against a series of constants.

When working on your own project you can get away with using multiple if statements.

It works and you know how to do it. However, rule of thumb states: if you are using more than two if statements, you should use a switch. Switch statements are easy to use and look neater and easier to read.

A switch statement is set up similarly as an if statement.

You use the shared variable, and each case must be assigned the variable value, and each case needs to be ended with a break. Using switch statements makes adding additional variable values easy.

If you are working on a group project, using a switch statement will allow all parties involved to be able to quickly read the code and understand what it represents as well as making adjustments easier for the group.

Now that you know what a switch statement is an how to utilize it, you can now add this tool to your set and become an even better developer with it.