Switch Statements to the Rescue
Jun 3, 2021
Objective: Optimise code using switch statements.
Using if statements can have its uses but when it comes to multiple options and values, there are better ways to implement logic. One example is using switch statements. These can be more readable and efficient.
They work very similar to if else but with slighly different syntax and layout. They start with the switch key and go between the variable values using cases with each case ending with a break to seperate the logic between cases. There can be a default case as a fail safe option but that will depend on what is being tested against.
In the next post, we will start on the user interface.