In this lecture, we're continuing our discussion of the selection control structure. Here are the module learning objectives for the module. Last time, we talked about the different variations of the if statement we could use to make decisions in our program. This time, we're going to look at another C# statement we can use to implement the selection control structure in C#. And that statement is called the switch statement. So, now you should go do an in-lecture quiz to see if you paid attention to my previous sentence. I have already built a project that demonstrates the switch statement. Although it doesn't really do any of the demonstration stuff yet, if I Ctrl+F5, do you want the shiny thing? Yes, no, h, whatever, press any key. So, this is exactly as before, this is exactly as before. This is the part that we're going to do slightly differently. So the new statement we're looking at is the switch statement. And the way the switch statement works is we type the word switch, which is a keyword. And then in parenthesis we put the name of the variable or an expression if we choose to. That we want to switch on basically, that we want to evaluate its value and take appropriate action. So, before we had answer as a key portion of our Boolean expressions. And it turns that answer is exactly the variable that we want to switch on here. The syntax is a little different, well maybe a lot different from the if statement. So for the different values that the answer variable can have, we add cases. So we have case, lower case y. I'm going to compare this to i, and I'm going to print that message that we used before, that I probably won't remember verbatim, but we'll remember it close enough. You have the shiny thing. Now, it feels like we should be all the way done here, but we're not quite, because as you can see, we're getting an error message. And that error message says we can't fall through from this case to other cases. Other programming languages let you do that. And sometimes that's really useful, and other times it leads to horrible bugs that take hours and hours to find. So C# doesn't let us do it. So at the end of every case we do, we're going to type the word, break. When we do that, that compilation error goes away. And now, we have a form that will behave exactly like our first if statement worked last time. When I Ctrl+F5, if I say lower case yes, I have the shiny thing. If I say h, nothing. And sadly, if I say upper case Y, I still get nothing. So it turns out, that we can list multiple cases, multiple values for the answer variable in this particular case that will do this stuff here. And so, if I just stack these values like this, then I can check both answer being lower case y and the answer being upper case y. And it will do this in both cases. Let's check it to see. Lower case y still works the way we expected. Now upper case Y also gives us the shiny thing. And finally, we'll check that h, nothing. So, we can do the same thing for no. Where we don't have the shiny thing. And I pressed F5 by mistake so it flashes right away. Let's try that again. Lower case n, don't have the shiny thing. Upper case n, don't have the shiny thing. Still showing you that y works in both cases. And, of course, h still doesn't give us anything. Now just to, so this sort of works in a similar way to the if, else if, else thing. Where it figures out which of these things matches, if you will, and does the appropriate stuff inside. I'll point out that I cannot down here decide, oh I want to do another thing with lower case y, because that has already been included. We've already used that value in a case, so we can't use it again. You might wonder though, how we can go about doing that your a noob message. Because we sure don't want to have to say, case a, case, upper case A, case b, all of the other possible characters that are not y or n. What we really want is something that corresponds to the else in our if statement. And luckily, we get such a thing in the switch statement. We type the word default. Which really means, if none of these other things match, then do this instead. And here's where we can do our new message. And, we're still going to have to add a break, because we add a break at the end of every clause we include in a switch statement. And now, when I Ctrl+F5, I'll still check y. I'll still check n. And I'll try h where I get my new message. So, you might wonder why we care? If we already have this if else, if else structure, why would we want a switch statement instead? And it turns out that I covered it here because it's sort of the other statement we use for selection in C#. We find it to be most useful in our game development when we're using something called an enumeration. An enumeration is basically a data type that has specific values. Don't worry. We'll look at enumerations and see how they all work so, so no worries that we haven't talked about it yet. But we'll discover that when we're using an enumeration, we find that switch statements tend to seem a little more intuitive as we implement them. I'm going to have you, if you do the optional lab, I'm going to have you do some practice with both if statements and switch statements, because they're both useful tools for selection. And you'll pick the most appropriate one as you continue on with your programming. So next time, we will start talking what, we've talked about two different C# statements. Next time we'll show using selection in actual game situations.