 Welcome to the video lecture where we are going to discuss about the decision control statements if else if ladder. This is in the continuation with the previous three videos where we were discussing about different types of decision making statements used in program language C. Learning outcome, so at the end of this session students will be able to write C code using if else if else ladder statement. So what is this if else if ladder statement? If else if ladder statements are basically used for implementing multi-way decision making statements inside. Put it in top of the ladder to the downwards flow of execution. So for each of the conditions which have been mentioned in the program all of these will be checked one by one. If all of the condition there is nothing but test one will be executed then it will move ahead. If it is false then it will move ahead for checking the test two then if it is also false then it will move ahead for checking out the test three and then we will move ahead to default option. If none of the tests are being evaluated to be true then by default else block will be executed. So else block is executed when all conditions evaluate to false. Let us look into detail how exactly if else if else statement executes in the program by with the help of FROCHAP. So first of all test one will be evaluated. So if it is true then we will go for the program will grow for executing these statements belonging to if and then these statements below the if else if ladder will be executed. So as you can see here this test one will be first of all checked. If it evaluates to true then if block statements will be executed. So in this fashion the arrow indicates how the program will continue to execute. Now what if this test expression evaluates to false then it will go for checking out the test number two that is nothing but else if block. The condition mentioned in the corresponding expression that is nothing but test two will be checked. If it evaluates to true in that case the statements belonging to else if block will be executed. So if this test expression evaluates to false then the program will come for checking out the test two expression. If it is true then only else block statement will be executed. Then again the rest of the statements below if else if ladder will be executed. So this particular arrow indicates that how the program executes while the second test is being evaluated to true. Now what if this test two happens to be false or if its corresponding output happens to be logically false in that case the corresponding else block of statements will be executed. So this must be noted that if test two is false then the program will continue to checking for the test two then it must be noted that if test one evaluates to false then program will continue to check for the test two. If it is also evaluated to false then by default else block will be executed means what no condition will be checked in this case. So in the previous slide we had discussed that if all of the test cases evaluated to false in that case default else block is executed. So what is the syntax of writing if else if in the C program ok. So first of all we need to mention if keyword followed by test one and the corresponding block of statements if this particular test one happens to be true ok then we will write down the else if keyword ok it must be noted that else is there is a space in between else and if. So if this test two happens to be false or if it evaluates to logical true value then the statements which have to be executed are imposed within pair of curly brackets. Then at the end we have else block of statements so this particular else block will be executed if test one as well as test two are evaluated to false condition. This else is optional either you can use it in the program or you may not use it in the program. So these syntax is as per this time to reflect go to the program given over here very carefully and try to find out the output of this particular program pause the video for a moment and think about it. So as you can see here two logical and operators have been used in the program is not it. So if else if else if statements and else block has else statement has been skipped as we said that else is optional ok. So we have used logical and operator inside the program ok. So we know that logical and operator is used for checking that if both of the conditions are true in that case only the corresponding condition a bar is to 2 and only in that case if statement will be executed ok. So pause the video for a moment and think about it what can be the corresponding output of the program. I hope that you have got the corresponding answer. So everywhere all the conditions should be satisfied. So for the given values of x, y and z we say that x is not greater than y so if condition is false then the program will continue for checking the next statement or next condition. So y is greater than x this condition is true but whether y is also greater than z no this condition is false and hence this total condition a bar is to false and therefore the program will go for checking out the third condition. So as z is greater than both x as well as y the corresponding output will be z is fake ok. So what is the output it is nothing but z is fake. Try to write a program using code blocks inside here I am going to declare certain number may be n ok. So this number is going what is in this program what we are going to do we are going to check whether the entered. So the given problem statement is to check whether the given number is positive negative or 0 ok. So let us declare a variable n which is going to hold the number entered by user ok. So we may use certain statements such as printf. So printf is we are using scanf statement and inside that we are using percentage d as the format specifier because we have declared integer variable ok. So this is for scanf statement is used for reading the number ok. Then how to write down the condition see we need to check whether the given number is positive negative of 0 ok. So in general how do we decide whether number is positive negative of 0 basically we go for writing some condition that if a number is positive it should be greater than 0 ok. So we will write down the condition as if n is greater than 0. So this is the first condition. So this is for checking whether the condition without the number is positive or not ok. So in that this case we will write that n is or we can display the given number as well and is positive ok. Now what if this condition happens to be false how we are going to use that then we will write the keyword as if followed by a pair of round brackets and inside that I will check one more condition. Now for a number to be negative we need to include the condition as n should be less than 0. So this is for checking if the given number is negative or not ok. So in that case again we will write down that the given number is negative ok comma n. Now what if both of the cases are wrong then what we can do is either I can write else because if the number is not positive number is not positive if the number is not negative then by default it will be 0 ok. So I can write that the given number is so this is we have not used any condition for checking whether the number is positive negative because see what will happen if this condition is true this condition is true in that case this statement will be executed. If it is false then it will check for the second condition if it is also false then since we know that else is the counterpart of it and if the condition happens to be false automatically else block gets executed ok. So this is how we have written the program. Now let us try to build it and since there are no errors let us go for running it maybe I will enter a number may be 100 ok so the 100 number is positive the corresponding output we have got ok. Let us rerun the program and give a negative number may be minus 120 ok so 120 is negative the program output is correct one ok. Let us give one more value 0 ok. So what if I want to skip writing else in this program then I can know for writing one more condition and in this case I need to check or equate the number I need to compare the n value with the 0 and this is for checking if the number is 0 or not ok. So again I will build it and I will run the program so if I enter now 0 again I get the same output so in both ways you can write down the program ok. So this is how we use if else if ladder inside C programs ok particular video lecture was created by using following reference books.