When working with 'if statements' we are going to have some decisions to make about how to structure our code. In this lecture, we will examine two problems, and explore alternative solutions involving 'if' for each of the problems. This example problem involves two grades; grade one, and grade two. We'll give grade one the value of seventy, and grade two gets eighty Now, there's an if' lif statement' on lines four through seven. There's a Boolean expression associated with the if, and another Boolean expression associated with the Lif. These expressions are evaluated from top to bottom. And when one of the expressions is true, the body associated with it gets executed. And the if statement exits at that point, without continuing on to evaluate the subsequent expressions. Because of that, at most one of the two print statements will get executed in this case. So, let's look at this code. If the grape one is greater than 50, and it is, we're enter into the body of the if. And at this point, becaue one of the expressions associated with the if was true, the if statement will exit after executing this body. So we jump down to line nine. In line nine there's another if statement and on line eleven there is a third if statement. The condition associated with the if on line nine is the same as the one on line four and the condition associated with the if on line eleven is the same as that associated with the Lif on line six. However because this code from lines nine through twelve is two separate if statements, as opposed to the if Lif that exists on lines four through seven. It behaves differently. We first evaluate the expression associated with if online nine, and it's true. So, we enter into its body and print the message. And, at this point we will exit that if statement, moving onto the subsequent code. And, that code is line eleven, where there is a separate if statement. This Boolean expression is also true, so in this case its body is executed as well. So the if Lif is not equivalent to two if statements. And we need to take that into account when we're running our code, and take care to use the appropriate structure in each situation. Let's consider another problem. This problem involves predicting whether we should bring an umbrella or not. So we'll take into consideration whether precipitation is expected using a true or false value. And what the temperature is for today. The temperature, in this case is +eight degrees Celsius. This if statement for it checks the condition to see if precipitation is expected and that is true. So we enter into the body of the if and in the body there is actually another if statement. One if statement is nested inside the other. We can then check that boolean condition and find that it is true, so we print the message bring your umbrella. I want to modify this code so that we write a second version without the nesting. Notice that when precipitation is true, the condition associated with the first if, and the condition associated with the second if is also true. That's when we print bring your umbrella. So they both need to be true. We'll use the Boolean operator "and" to state that, and that was we can structure this as a single If statement. Let's visualize the execution. In the first case, the variables have values that, causes to print Bring Your Umbrella. And, in the second case, we evaluate this Boolean condition, precipitation refers to the value TRUE, temperature refers to the value +eight, so this expression is also true, and the message Bring Your Umbrella is displayed. Now, let us expand on this example. I'm going to add an Else to the if statement on line five. This else describes the statement to print when temperature is not greater than zero. I'm going to now edit the code on line ten to make that if statement equivalent to the one on line four. Let's look at the conditions under which the Else code executes. The precipitation condition needs to be true, the temperature greater than zero condition must be false and then the Else is executed. So we can express this using an L if. We want to make sure that the first condition is true. And we don't need to check the second condition. Because we'll only reach the L if when that is false. In that case, we'll print the same message as above. Let's visualize the execution now. In fact there's one more thing to do. Let's make this a negative three so that it's below freezing and we print those messages. So if precipitation is true, we enter into the body of the if. Checking this condition, because I just changed what temperature refers to, it's false. And we print the statement from the Else. In the second If statement, we check the first condition, which is false because the temperature is not greater than zero. Now we must check the L if clause and this condition is true, so we enter into the body of that L if and we print the same message. So these two pieces of code are