Control Flow: Switch

In this lesson, Codecademy introduced the concept of a switch control flow. Using multiple if, elseif, and else statements nested within each other can make code difficult to read and messy to look out. The switch control flow can simplify code substantially, and work similar to an if statements. If a condition is true, then the correlating block of code will execute. Each switch control flow contains cases which will execute if the condition matching them evaluates as true, and a default case that will execute if the condition does not match any of the given cases. The following code is an example of a switch statement, and will echo "$i is somewhere between 1 and 5."