We've got the hang of if statements now. We check a condition, and if it's true, we execute some code. That works, and it's very handy, but what if we want to run some code if the condition is false? That's where the if-else statement comes in handy, it looks exactly like if statement, but before the statement closes, we can add
The code for an if-else statement looks like this:
The above code is the exact same as our original if statement, except now we have added some code to execute if the original condition is false. If we are on the Storefront page, we will see "Welcome to our awesome site!", but if we are on ANY other page besides SFNT, we will see a nice promotion for our sale on men's shirts.
The code for an elseif statement looks like this:
If you look at the code above, you'll notice that we are checking for the same condition as our original if statement, is the current Screen the SFNT. Immediately following that statement, rather than close the if statement, we put an elseif right after it. This time, we check if the Screen is PROD, if it is, we display a message about free shipping. If neither of those conditions are met, we exit the if statement and don't run any code at all. You can chain as many elseif together as your little heart desires.