 Hey, welcome to Intro to AP Computer Science for new AP teachers. This video is about conditional statements, a very important topic indeed. So here's what I'm going to try and cover. So I'm just going to go over the basic if statements, the comparison operators, logical operators, including a concept called short circuit evaluation, looking at else and else if. Again, we want to revisit determining membership. So for example, is something a vowel. We talked about that previously in the strains unit. Also important topic, equivalent Boolean expressions and how to determine if two expressions are in fact equivalent for all values. And then we have an introductory exercise, building on what we have done previously. So the first thing is the basic if statement. So students, it's a natural concept. Students will understand if this, then that. In fact, this is what I tell my students starting like in grade five. I tell them the secret to coding is four words, if this, then that. If they understand that concept, they are good to go. So they just need to understand the other. We have a condition and we'll talk about conditions in a minute. And that condition actually always evaluates to a Boolean. It's either true or it is false. And they've seen this with, they will see this with loops as well. And then there is a code block. So the use of the braces determines where that code block starts and ends with what is part of that if statement. Now in Java, if you don't have the braces, basically it's just one line. I don't really talk about that with my students because I don't want them to get into the habit of forgetting it. So I never, I don't really tell them that's possible, although they do see it from time to time. They need to review that when you're comparing, always start with equals because that's the easiest one I think conceptually. Just remind them that with primitives, we use a double equal sign and with objects, we use dot equals. So for strings that we dot equals for an int, it would be two equal signs. This is actually also where I introduced the scanner class because now that we can do conditions, we can now also get input from the user and have them, you know, just input stuff and then compare. This is where we can start doing like guessing games, this is where we can start doing, you know, input a couple numbers, doing some math, that sort of thing, instead of just hard coding everything. So if you're not familiar with the scanner class, check that out. Again, it's all in my book, my ebook, and then you have dot next line. If you want a string, dot next int gives you an integer, go figure, and dot next double will give you a double. Then I go into the comparison operators. You have equals greater than, less than, greater than or equal to, less than or equal to, and not equal. It's kind of important to point out that the exclamation point means not because you'll see that later with the Boolean expressions. One thing you just want to go over is does five equal 5.0? And the answer is yes, it will give those things the exact same, it will evaluate the true accuracy. And then again, I just, you know, students need to be reminded, don't use equals with double equal signs with objects. The results are not always what you expect. There is a time and a place to do that when you're determining are they the exact same object. But for most of our purposes in this course, you don't really need that. It just stick with dot equals and they should be fine. Again, I try to limit what I teach the students to the AP subset as much as possible. I want to go a little bit outside of it, but, you know, the test is very important. The results are very important for college admissions. So I really try to not confuse things where I can. Then we have the logical operators. This is used to chain conditions together. So for example, you know, is it Tuesday? Is it after 5pm? Yes, we get a discount. So it's not just one condition. It is two or maybe three or four or five can be as many conditions as you as you want. So rather than nesting your if statements, you can combine them into one. Now in Java, we use the double ampersand for and and double pipes for or. So students coming from say, you know, Python, which I have quite a few. You know, they just they just need to be aware that we don't use and or the English words we use and and ampersand ampersand and the pipes here. And then the other one, this is a concept kind of interesting is short circuit evaluation. So sometimes we only need to check the first conditions. So the example I just gave, you know, is it what I say is it Tuesday? Is it after five? So if we go, is it Tuesday? And if it's Wednesday, do I need to check? Is it after five? The answer to that, of course, is no. So as a thought of efficiency, you know, if something is rare, you know, would you put it first as a condition or last as a condition? You probably put it first as a condition with and is that way there's less calculation that needs to be done. Now, I know computers are fast these days, but it's always doesn't hurt to get in the habit of thinking about efficiency. And then, of course, going into else and else if basically else, of course, is used when there is no other condition that is true. So for example, you know, is it Tuesday? So if it's Tuesday print, it's Tuesday else print, it's not Tuesday. So it can't be Tuesday and not Tuesday at the same time. There's only one possibility there. And then else if allows you to check for multiple conditions only one of which is true. That's an important point. So these these options have to be mutually exclusive. So the example I give in the ebook is if grade equals 12, then print your senior else if so else if if you're not a senior. Let's check if you're junior if grade equals 11, grade equals 10, grade equals equals nine. And then I have an else statement there. So the else says, okay, you're not a high school student. So based on the possibility, so you're either 12th grader, 11th grader, 10th grader, a ninth grader, or you're not a high school student. So that is our default option at the end, our catch all. That's a very common thing you'll see in coding, of course. Determining membership revisited. If you recall from the strings unit, we looked at determining is something a member, does something exist in another set in another collection using index of. So the example I think I gave there was vowels. So A, E, I, O, U and capital A, E, I, O, U. So now we can actually combine this instead of just printing out true and false like we did earlier. We can do if the index of a letter is greater than negative one, it is a vowel. So this lets us determine membership. And then you can kind of walk the students through an example and say, okay, I want to do the same thing. And I want to know if something is a number. So is it a number from zero to nine? Just to keep kids thinking of it that way, okay? And so just kind of, again, we can get more complex. The example we gave previously was, you could put a list of all the names in the class, you know, inside of one string, call it seniors. And then if index of, that's not how you do it in real life. But it gets them used to the idea of thinking of data as sometimes a collection of things. Yeah. And then the last topic I think in this unit is equivalent Boolean expressions. So the question is, are these two expressions the same for all cases? So we have two variables X and Y. So one approach is to do what's called a truth table. And that is where you just basically make a chart. So basically you have two variables. So true, true, true false, false, true, false, false. You have four possibilities. And you just go down through and you calculate, is this true, is it false? And then compare both. The other option is something called De Morgan's law, which again, check out the book. It's explained there. But that's a bit of a complicated one, but it's really, really helpful because there are questions about this on the AP exam. The truth table method works, but it's slow. De Morgan's law is faster, but a little bit more prone, I think, to error. So, yeah, it's something that the students should be aware of both possibilities. And then here is the introductory exercise. As you've seen from the past few videos, if you've been watching along, basically what we're trying to do is choose objects and attributes, get them used to thinking about data, data types, and how can we relate what we're doing to the real world. So they can build on what they did before if they still have that on their computers or still have access to that, or they can start fresh. And I like that the students work in pairs on stuff like this, and it seems to work out pretty well, especially because coding tends to be a very isolating activity most of the time. So then basically they could just come up with some criteria and give, you know, phone A and phone B a rating. So, you know, for example, phone A, if the cost is less than $200, give it an extra rating. So, you know, one star because you might be cost, very cost conscious. Well, another student might say, well, if the phone cost is over $1,000, you know, plus two because they think they want to show off that they have money or whatever. So there's the coding side of it. There's the object side of it and there's kind of the value side of it. What do you value when evaluating a certain thing? You can get some really interesting results out of that. So that might help you get started and to, you know, help the kids get started thinking about how this relates to the real world. So we looked at the basic if statement, the comparison operators, the logical operators, short circuit evaluation, else and else if, determining membership, which is, again, a very useful skill. And especially as you start, you know, learning about more advanced data structures, you know, right now we're just doing strings, but it's pretty cool. And then equivalent Boolean expressions and we had an introductory exercise. You see exercises in a slightly larger font there. I missed that. Anyway, thanks for watching. Take care.