Hi everybody, welcome back. Earlier, we talked about how you can add If statements in order to effect the flow of control of your program. What you need to do is you go through, and you kind of circle those little decision points in your code where the computer needs to make a decision whether or not it's gonna execute this code, or maybe that code. In our earlier examples, the decision points tended to be pretty simple. But, it's not always going to be that way. What if you need to check for two conditions? Or, what if one condition depends upon the value of another. I'm sure you can think of lots of everyday situations where, when you make decision, it depends on more that one thing. Even if you're gonna go to a movie, you need to decide. Is the rating okay? And it is as much as I wanna pay. So let's talk about what we call nested If statements. It's possible to put one If statement inside of another. So, in this situation I have an If statement right up here and then I have my boolean expression in some where inside my block and the programs working it's way down it says op, here's another if statement and another boolean expression. In which case we have two blocks to our program. We have a big outer block, but we also have this kind of small inner block as well. Now, here's where the logic comes in, it's important for you to understand I will never get here. Ever, ever, unless both boolean expressions are true. So, the first thing I'm gonna say before we even go on with this, is that it's so important that you think about your code, and you plan ahead. Because, as we start to make these more complicated or more complex decisions points, you want to make sure that your logic is correct. So what about else statements. I talked before about how you can nest If statements inside of each other. Well, if you want to have an else statement along with those If statements its important again to think about the logic. Because an else statement always matches the most recent open if statement. Indentation, where you put your code, whether you put an else directly below an if, has nothing to do with it as far as the computer is concerned. It's all about the curly brackets. Lets go ahead and build on to that nested if we were doing before or that If statements we were doing with that name before. The difference is, well, earlier we were simply respond and say, Hi to whatever name they put on. We want to be a little bit more complex. We're going to leave that same part where if they don't enter anything or going to say, Hey, are you feeling shy? But now, if they do enter a name, we want to do different things depending upon what they enter. So if they enter any regular name, I'm gonna go ahead and still just leave out, Hello whoever. But, if the name they happen to enter is say, Colleen, we're gonna print out what a beautiful name. So we need to think about the decision points we're setting. First, we have to decide, did they enter a name or not. When we think about that, that gives us this first big outer block. Then, we need to think about each of the different cases that might happen when we enter a name. And so I have my if, name, and again it's ==, not =, but ==. That's how you check for equivalence. If name == Colleen do one thing, else, do another. Now the reason why this else statement right here matches this one is that it's the last one that's open. Because what we don't want to happen, is if someone enter in an empty name, we don't want this else to suddenly go, Hello emptiness. We want it to again skip, and go all the way down here. Hopefully that'll make a little bit more sense, as soon as I run this. So first, let's go ahead and put in my name. There we go, exactly the output we were hoping for. What if I put in a different name such as. Well, then we get the Hello Catherine. Finally, if I try it one more time and I don't put anything in at all we get that last message of feeling shy? So you can see that by adding these different if statements I've created different levels and different outputs depending on what the person put in. Now, I want you to look closely again at this code one more time. As you can see, when I get to this statement. Let's say, right here. I'm basically saying that name.length isn't equal to zero and the name equals Colleen. This statement down here, I'm basically saying the same thing as if name.length doesn't equal zero and the name doesn't equal Colleen. Each one of these bits of code could actually be written with more complex boolean expressions. Let me show you what I mean. Right here, I've replaced my nested if statements and replaced them with much longer conditional statements. Much more specific. We might also say conditional statements. This code works and it's absolutely fine but it's much less efficient than nesting the different if statements. And here's the reason why. When the computer runs to this code, it does this if statement. If it's true, it executes the code, but then it still goes down and it checks this one and that one as well. So we're not really doing flow of control as much as just checking one line at a time. In our previous example, if the computer sees that the name is empty, It skipped all this and it jumped all the way down here. In a similar manner, if the computer see's that this is true, it skips all the way down here. So when we write these flow of controls, in these small programs it may not seem like much, that we're skipping two or three lines of code. But you can imagine how in the long run it could really make a difference. So what do I want you to do in this class? I want you to do whatever you are comfortable with. It is possible to create complex flow-of-control in a program using if, else, and different nested statements. It's also possible to get your programs to work putting in these complex conditional statements. The most important thing to me, and hopefully to you at this point, is writing code that you understand. So follow along with my code. Make sure you understand it. But when it comes to writing your own code, I'm not as concerned that you necessarily do it the same way I did it. I want you to write it so that you understand what you're doing. So go out there, code as much as you can, play with the examples. I promise that I'll provide more so you can keep practicing. Good luck.