 Hello everyone, welcome to the video lecture where we are going to discuss about the control statement if else. This is in the continuation to the previous video where we discussed about the decision control statement if, learning outcome. At the end of this session, student will be able to write a C code using if else statement. Now, in the previous video we had discussed how to implement decision making statements in C. At that time, we had said that there are multiple ways of implementing decisions such as if statement, if else statement, if else if ladder as well as switch statement. So, at the time of implementing if we had discussed that if the condition is true or if the condition is being met certain actions will be taken. But what if, if the condition is not being met the program was not doing anything. So, in this case we need to discuss about what is the need of if else. Basically, if else statements are used for implementing either or situations or these can also be called as a two way decision making statements. Let us take an example, I want to decide whether a person is eligible for voting or not. I know that if the person's age is greater than 18 he is eligible for voting. I need to decide whether I can avail senior citizen concession or not or in a business whether I incur profit or loss. If you observe carefully all of these questions have only two answers that is nothing but either yes or no. So as to implement this kind of scenario where we need to implement certain kind of actions based on one condition and certain kind of situations or statement based on exactly and another set of condition then we go for using if else. So think about such real life scenarios where you think a two way decision making statements can be used. You can pause the video and think about it. Let us move ahead for checking how exactly if else works okay. So this is the test expression in the previous video as well we had discussed that in the text expression we basically use relational operators. So these relational operators based on their output or what is the corresponding output that whether it is true or for certain actions will be taken. For example, if it is true then the statements written within the body of if will be executed and the program will continue to execute statements exactly below it. What if the corresponding test expression evaluates to false in that case the body of else will be executed and the then program will continue to execute statements written after the if was blocked. You must note that in the scenario if this is the true these statements will be skipped from the part of execution. While as if the condition is false in that scenario these statements will be skipped from the part of execution. Okay let us take an example. I will give you two numbers 10 and 15 out of these which one is the greater one you can say that 15 is the greatest number okay. So how do we implement this in the program okay. So I need to compare two numbers A and B. If A is greater then I will say that A is greater and in that case then again what if if A is not greater that means B is greater than A then I can write that B is greater than A okay. So again here we also observe that there are two ways of implementing the statements or there is a two-way scenario two-way decision making hence we go for using a false statement okay. So moving ahead into technical details how do we write actually if else in C so what is the syntax. So according to syntax the keyword if is followed by test expression and if it is true the statements which have to be executed are enclosed within the pair of brackets while as the statements which have to be executed if this condition evaluates to false those are included within the else block. So it must be noted that if and else both of these are keywords from C language okay. Now let us actually try to write a program by using code blocks we are going to compare two numbers whether out of the two numbers which one is greatest and for that I need to declare two numbers. Let us take these two numbers maybe A and B so both of these are going to hold the values entered by user. Let us ask the user to give two values so it is enter two numbers and since we are taking two integer values let us use scanf %d %d as the format specifier for reading the two integer values and using the ampersand n sign implying that we are putting the address of the variables okay. So how do we write the actual program? So first of all we need to write the keyword if followed by pair of round brackets in that I will write down the condition. So what is the condition? I need to compare two numbers so for that I will compare by using the relational operator whether A is greater than B so I can write printf %d is greater. Now it must be noted that since I want to display a integer value I will again use %d as the format specifier okay. What if the condition is false then I will write we have written the statement for the else block. Now here you should note that the default scope of if statement as well as else statement is the immediate block of immediate statement following the if. Now if I want to write multiple statements in that case I can go ahead for writing the statements within the pair of curly brackets. Now after running the program the corresponding message has been displayed on screen so I will give two numbers may be 10 and 20 okay. So here we can say that 20 is being largest the program displays you correct output. Now here it must be noted that since this condition is false therefore this statement has been skipped from the part of execution okay. Let us rerun the program I will give two different values may be 15 and 10. Now in this scenario A value is greater okay so according the program displays that 15 is greater so in this case the else part of statement has been skipped from the part of execution okay and this way we can write if else statement in the program. Write a if else block statement so as to check the eligibility of a person whether he can vote or not okay pause the video for a moment and write down the statements. I hope that you have written the answer so how to code the condition inside C the eligibility can be decided based on age. So if the age is greater than 18 then you can write the person is eligible for voting if it is not then you can display the message that the person is not eligible for voting okay. So while the time we discussed that decision making statements can be implemented by various ways we also said that conditional operator is logically similar to if else. So conditional operator is the single ternary operator which is used for implementing a two-way decision making. So what is the syntax for that? Syntax is nothing but we need to specify the condition followed by question mark followed by expression 1 followed by colon operator and followed by expression 2. Now how it is identical to if else block? So the first condition it implies condition implies that we are putting some expression or condition using relational operators then expression 1 is identical to if block in the execution and expression 2 is identical to else block. That means if the condition is true expression 1 will be implemented it will be executed while as if the condition is false in that case expression 2 will be executed okay. So the same program it can be written by putting this condition as if the age is greater or equal to 18 then we can say that the person is eligible for voting or else go for it is not eligible okay. So this is the single ternary operator in programming this is the single ternary operator used in C language also conditional operators can be nested as well. So what do you mean by nesting that we will look into the next video okay. Now again let us try to recollect how exactly conditional operators work. So here this is what this particular statement implies the that we are putting a condition. The statement this statement is nothing but expression 1 and this is nothing but expression 2 okay. Can you credit the output pause the video for a moment and think about it. I hope that you have guessed the corresponding output. So since this operator is nothing but not equal to operator so we are comparing two values 4 and 5 okay since 4 and 5 are not equal obviously this condition is true and hence this particular that is nothing but expression 1 will be executed. So what is the output? The output is nothing but if block of statement. So this particular video was created by using referring to these particular textbooks. Also there are multiple online tutorials and online resources available for further study you can always use them for practice. Thank you.