Hello welcome to the 13th tutorial a swift basics series and in this part we're gonna be looking at switch statements. switch statements are essentially a simplified if else if else statement allows you to check variable has a certain value and allow you to do stuff like if a value is greater than a certain value for example if you're trying to compare maps only numbers, but it's a good way to simplify if statements none of us open it up. I remember when I first came across the steps I always refused to use and put down like and but I actually do a lot now to start you. When you get more comfortable with it. You will use stuff a lot more and more. So create a variable called superhero assignment.
A runnin put Yoda, some may argue is not a superhero, I will say he is. So switch and this is the variable that you want to be checking salvos superhero, all of that video essentially. And then we put cases and each case is basically an if statement it check when we do if colon so you do case, then the condition, okay the value that you check your code on, and then you put any piece of code that you want to play its own code, print line DC, then do the same case on this basically elsif after putting any of that expert complex elsif stuff, stupid in 10 cents and then it's going to call more wall. Put case Yo, they're coming up point nine was and but you do have to have a default statement, which is the default statement is essentially your aos statement. So you can think of it if you compare it to an if else if statement flying in here I'm just gonna put not a hero everywhere in it.
It's a style so that's why that is this is the variable that you check in. And this essentially, does this variable equal Batman other superhero equal Batman. Nope. So it's not going to print the line DC. Does the variable equal Hulk so it's not it's not going to print the line Marvel movie yet some printed on style but if I just put in our next preview here, run it is not a valley superhero food check for the No no, no, they say that okay? else going to show you Batman runner essayed DC.
One thing to note is it is case sensitive. So for lowercase b is not a valid superheroes so So one last thing to notice obviously, you don't have to just use string here but any sort of data can use Boolean if you want to use an interior float, but I just use a string for the purpose of this tutorial. That's it for this tutorial. If you have any questions, feel free to message us support us on our system Cory K. email will be in the description you can comment on this video or directly messages via YouTube or the recordings full source code will also be in the description. And as usual, thanks for watching and have a nice day.