 Hello, welcome back. In the previous segment, we discussed the most general form of the if statement. In this segment, we are going to see a more general way of specifying conditions. Sometimes the simple conditions that we used may not be adequate. So now we will see a more general way of specifying conditions. For example, we might want to say that look, do this if some two conditions are met rather than just one, some two conditions are true or we might want to say that do this if one of some two conditions is true. So for this we need something called compound conditions and this is how we write them. So here is an and compound condition. So the way it is written is condition 1 and and condition 2. So we will see examples of this, but say you could write this as if x greater than 5 and and y greater than 7, something like that. So when is this condition true? Well, it is true only if both these conditions are true. So if you put this in an if statement and if say if you write if this whole thing as your condition as your compound condition, then you can the consequent is going to be executed if both of these conditions are true. I can have an or condition as well. So an or condition looks like condition 1, bar, bar condition 2. And the whole condition, this whole compound condition is deemed to be true only if at least if and only if at least one of these conditions is true. Both need not be true. If one is true that is good enough. So again, if you put this as a condition, this entire thing as a condition in an if statement, then the consequent will be executed if one of these is true. And finally, we have a not compound condition. This is written as the exclamation mark followed by a condition and this is true if and only if this is false. So sometimes you want to do something if the given condition is false rather than if it is true. So in that case, you can write by putting a not over here. Now the components or the conditions included inside a compound condition may themselves be compound conditions. So for example, you might write something like condition 1 and and condition 2 or condition 3. So this is allowed. So how does this work? Well, we first evaluate condition 2 or or condition 3 or condition 3. So that means we check is one of these conditions true. So we want one of these conditions to be true and we want condition 1 to be true. Actually the order in which we do the checking is from left to right. So we first check whether this is true and then we check whether one of these is true. So if this turns out to be false, then we do not even have to worry about checking this because we know that both need to be true for this entire thing to be true. If one of them is false, then the entire thing is false anyway. So why bother to check these conditions? So that works here as well by the way. On the other hand, if this was an R, so in this case, we would check this condition and then if this is true, we do not even worry about checking this condition because at least one of them has to be true and we have already found, if we have already found one to be true, we do not have to worry about checking the second condition. Anyway, so we can have conditions which are ands and ors and we can have even more complex conditions. So compound conditions which are themselves containing compound conditions. So let us take an example. So I can have a condition if income is greater than 180,000 and income less than 500,000. Do something. So do what? Tax equal to income minus 180,000, excess of income over 180,000, 10% of that. So when will this be executed? So when will this tax statement be executed? This tax assignment be executed? Well, so suppose income is 1000, then this condition itself is false. If this condition is false, we do not worry about even evaluating this condition because both of these conditions need to be true for this entire condition to be true. So in that case, the entire condition is deemed as false if income is 1000 and so this consequent is not executed or this assignment statement does not get executed. Suppose income is 200,000 or 2 lakhs. In which case what happens? Is this condition true? 200,000 is indeed bigger than 100 and 800,000. So this condition is true. But we do not stop over there because we need to check whether both are true. So then we execute this. So 200,000 is less than 500,000. So this condition is also true. So as a result the complete compound condition is true. So in which case this statement, this consequent will get executed. So tax equals now income is 200,000. So this statement will get executed. So we will get this will become 20,000 times 0.1 or the tax will be 2000. Finally, let us say income is bigger than income is equal to 600,000. So in which case what happens? Is this condition true? Is 600,000 bigger than 100 and 800,000? Yes, it is true. So if this is true, we should check whether this is also true. So in that case 600,000 is not less than or equal to 500,000. So this condition is false. So as a result this compound condition is false and therefore the consequent is not executed. So this is not executed. So what I mean by nothing happens is that the consequent is not executed. So the same condition may be expressed in many ways. So I can write income greater than or equal to 180,000 or I could have written 180,000 less than or equal to income. But I could also write this as not of income less than 180,000. And similarly I could write this condition as this. And therefore the previous statement can be written by using these forms rather than these. So this is just to alert you that conditions can be written in the same condition, the same constraint that we are talking about can be written in many, many ways. Let me take another example. Suppose we have a rectangle in the x, y plane. So this may arise in graphics or in geometry. So let us say this is our x, y plane. So this is the x axis, this is the y axis. In graphics the y axis goes downwards but let us not worry about that right now. So the rectangle lies between the lines x equal to 0. So this is, sorry, so this is the line x equal to 0 and the line x equals 10. So this is the line say x equals 10. And it lies between, also lies between the lines y equal to 50. So maybe this is the line y equal to 50 and let us say this is the line y equal to 70. So this is the rectangle that is of interest. So we are writing a program in which somehow say this rectangle is figuring. So maybe what is going on is that we have drawn this rectangle on the screen and then maybe we click and we want to know whether the click point is inside this rectangle or not. So let x, y denote the coordinates of a point possibly the click point and we want to know whether this point is inside the rectangle. So when would a point be inside the rectangle? So for this we will require that the x coordinate should be between 0 and 10. So x coordinate must be somewhere in this region and the y coordinate should be between 50 and 70. So between this region or in other words the point should be somewhere inside this. If any of these conditions does not hold then the point will be outside somewhere. So these are the conditions we that we need to check. So can we express this condition? So we can write this condition as 0 greater than or equal to x, x less than or equal to and x less than or equal to 10 and y greater than 50 and y less than or equal to 70. So if all of these conditions hold then really these conditions are holding and then the point will be inside. So if you want to check whether the point is inside we will have to say something like if this then take whatever action that is needed for the point if the point is inside or else take action if the point is outside. Now I just want to make one remark. You may be tempted to write these two conditions jointly in this manner but this is not allowed. This is not how you are supposed to write these two conditions. You have to separate them out and write them in this manner. So what did we discuss? We discussed general ways of specifying conditions and here I should point out that we had these operators not and and or and the not operator has higher precedence than the and operator which has higher precedence than the or operator. So what do I mean by this? So if I have this condition now there is some ambiguity over here. So the ambiguity is do I mean should I do p and q first and then take not and then take or or should I do it in some other order? So this says that not has higher precedence. So that means this not p should be done first. So I have indicated it in this manner by putting parentheses then and has higher precedence than or. So after that I want the and to be evaluated. So that I have indicated this manner and after that sorry and to be evaluated. So I have indicated that in this manner and finally the or should be evaluated. So that happens now. So you can always put parentheses explicitly but if you do not put the parentheses explicitly if you write it in this manner then c plus plus will use these precedence rules and then the precedence rules will say that look this is what we will what c plus plus will execute. Now my preference is not to rely on precedence rules. My preference is to just write the parenthesis. So that it is it is very very clear. You do not you do not want to tax anybody's memory if somebody or if you are yourself reading the program later if you put the precedence then if you if you put the parenthesis then it is it is very clear and you do not have to tax your memory. So in the next segment we are going to take a somewhat large example what we are based on what we have learned so far okay a full program but before that we will take a quick break.