 Hello everyone, welcome to the video lecture where we are going to discuss about how to nest control statement if else within the programming language C. Learning outcome at the end of this session students will be able to write a C code using nested if statements. Now when we are going to discuss nesting if else statement then we must know what does nesting means. Nesting is nothing but putting one kind of structure into another. For example, I can see that for example, you can see here that I am enclosing circles within different circles. So, nesting is nothing but basically enclosing of control structures one into another and this is implied in the program by different indentation levels. Now let us look into detail how nested if works actually. So, here we are using test 1 for checking one particular condition. So, if the test 1 evaluates to true in that case we are putting one more if condition within the test 1 itself. Now if this test 2 also evaluates to logical true in that case statements which we have written within the if block of test 2 will be executed. That means that for execution of these if block statements test 2 as well as test 1 has to be evaluated to logical condition true. Now after execution of these statements then program may continue to execute the statements whichever has written after the nested structure. Now what if if the test 2 happens to be false in that case if we have written any else block statements those will be executed or else the program will directly continue to execute statements just below the nested structure. Similarly, if the test 1 happens to be false then all of these statements will be skipped from the part of execution and the program will directly continue to execute the statements after the if else structure nested structure. What could be the syntax for writing these statements inside C? So, as you can see here first of all we must write down the keyword if followed by test 1 and then you can write down the statements which have to be executed if this test 1 evaluates to logical true. In the same if we are including one more if structure followed by test 2. So, the statements which are written in block 2 will be executed if test 2 as well as test 1 is evaluated to true condition. So, in this way we can nest one if else another inside another if statement. So, this particular syntax or this particular structure is called as nesting within if block of statement. Now is it the only case where we can put if else structure within only if we have one more scenario where we can nest if else within the body of else statements. So, here as you can see here test 1 will be evaluated first. If it happens to be true then if block statements will be executed if the test will evaluates to false in that case we have included test 2. That means that we are putting test 2 which is nothing but indication of another if else block. It has been included within the counterpart of if that is nothing but else. So, if this test 2 happens to be true then the nested if statements will be executed. If this test 2 happens to be false in that case the else block of test 2 will be executed. So, in all of the three scenarios after executing the respective if or else block statement the program will continue to execute statements just below the nested structure. Now what could be the syntax for writing this? As you can see here we are writing the keyword if followed by test 1 and the statements belonging to first if it is followed by the counterpart of if that is nothing but else and we are nesting test 2 within the else block. So, as you can see here if this the nested if statement have to be executed in that case test 2 has to be evaluated true 2 and test 1 has to be evaluated to false. So, we can also nest the if else statement within the else statement. So, this is called as nesting of statements within else block. Okay, time to reflect go through the given program and try to find out what could be the output of this particular program. Pause the video for a moment and think about it. I hope that you have got the corresponding answer. So, as you can see here we are writing if statement within another if. So, we are using basically nesting of ifs. So, what is the condition? The given value of n is nothing but 10 and 10 being greater than 5 the statements this condition evaluates to true. Hence, the programs will come inside the curly parenthesis of first if. Therefore, after coming the test 2 will be evaluated which is nothing but modulus operator. So, modulus operator is used to check the remainder. So, 10 modulus 2 is it is equal to 0. Therefore, both conditions that is nothing but first if as well as second if statement both of them are evaluated to true. Therefore, this print test statement will be executed. So, what is the answer? Answer is nothing but nested if will be printed on the screen. So, let us try to write a program for finding out greatest number among the three given numbers. We will use code blocks for implementation of this. As you can see here, we are declaring three different variables for getting three numbers from user. So, printf statement is basically used to display the message and we will be using scanf statement. So, as to read the three different numbers from user. So, how to write down this within a NEC program. So, first of all we are writing keyword if followed by the condition. Now, when I want to find out any number which is greatest among three, I should compare the number with rest of the two numbers. For example, I am giving you three different numbers as 10, 20 and 30. So, out of the three, third is being greatest, third is greater than 20 as well as it is greater than 10. Therefore, first of all the number A is compared with B. If it is greater, then only it will be compared with C as well. Now, if both of the conditions will be satisfied, then we can say that the corresponding number A is greater. Now, if this condition happens to be false means what? A is not greater than B. In that case, the program will come inside the else block of statements. So, in this case, first of all the implication of A is not greater than B means that either it is less or it is equal. So, in that case, we should compare value of B along with C. Now, if B greater than C is also true as well as B greater than A is also true. Therefore, in that case I can display B is greatest one. If all the three different scenarios happens to be false in that case, automatically the else part of statement will be executed. So, as you can see here, we are putting if else block inside else as well as we are putting if within another if. So, we are using nesting of if structure. Let us try to find out its corresponding output by running the program. I will give three different numbers as 19, 35 and 90. So, which one is the greatest? 90 is the greatest number. So, the program is showing you the correct answer. Now, what if I give some different values such as I will give the first value as 12, then 6 and then 7, 8. Now, as you can see out of the three numbers, the first one which is 12 is greater among the three. So, as you can see here the program shows you the correct answer as 12 is the greatest one. So, in this case the first condition 12 being greater than 6 as well as 12 being greater than 8 both conditions being satisfied. Therefore, this print up statement will be executed. So, in this fashion we can go on giving different kind of values. So, as to check whether which number is greatest we can find out through this particular program. So, nesting if is nothing but using if else statement either inside if statement or within the else block of statement. So, this particular video was created by using following references. You can also go for using multiple resources available online. Thank you.