FAQ: Conditionals - Switch Statement

This community-built FAQ covers the "Switch Statement " exercise from the lesson “Conditionals”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Swift

FAQs on the exercise _Switch Statement _

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Still unclear why Switch is needed over an Else If. In the example with the cities, they seem to simply confirm you can do the same thing with Switch OR Else If. Any insight is appreciated.

1 Like

I’ve got some confusion…

The lesson made me believe that using switch was INSTEAD of the else if, yet the only way to pass is for ALL of it to be used? And if this is true, then the next question I had was how the switch knew the expression was [Tony Stark]-but if it’s not true, then I’m unsure how switch figures this out, exactly.

So, is it switch OR else if or is it switch AND else if (and WHY, oh why???).

Yeah I’m with @philiphy—I don’t understand the difference between switch and else if, especially if the results are the same and the difference in syntax doesn’t really save you that much time. Else-if syntax feels more semantic than switch, too, so I could see myself more readily using else-if and remembering how to do it if I was working on a project.

Looks like this thread is dead since no one ever replied, a little disappointed in that.


I Googled it and found that switch is probably a more advanced function than what Codecademy needs to teach at that point in the Swift course. The benefits just aren’t clear yet, though it makes sense to teach it since switch and else-if are so similar.
The switch function is “exhaustive”, so it’ll spit back an error if you forgot a case. An if-statement won’t. That’s the main benefit that’s relevant to someone at this point in learning Swift, I think. There are more but they wouldn’t make sense yet. I think if the module simply explained this then it would mitigate confusion.