C_30 else if ladder in C | C Programming Tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the series of learning programming in c we are discussing about control statements in c we have already discussed if statement if else statement and nested if statement in my previous videos in detail with some examples and programs and their general their syntax and their structure using the flowchart right so now in this video i will talk about else if letter everything about else if letter this is also known as else if statement right so everything about this lcap letter will be discussed in this video with the help of a flowchart means the working of this elsif letter with the help of flowchart the general syntax and how to use this thing in a program and what kind of mistakes you can do when you write elsif letter in your program and the working of this thing with the help of a program and we will see the output of that program also so everything we will discuss about the celsius layer so now let us discuss about elsif letter or you can say elsif statement it is you can say use it is used to test multiple cases or it is known as multi-path decision it is used to take multi-path decision now what does this mean first of all uh see the syntax of this else if letter how to write this in a program we will write if okay if i am writing condition condition 1 suppose right and if this condition is true then suppose this statement would be executed suppose statement 1 i am writing here right after that you will write else and if we will write another condition suppose i am writing here condition 2 and if this is true then what statement 2 would be executed again else if condition 3 and if this is true then statement 3 would be executed see here i am not putting curly braces because i am considering that this is only a single statement if you write here block of statement then you can write down curly braces curly braces curly braces here and you have to write down curly braces for multiple statements right otherwise what error you will get that i have already discussed in the previous videos right up to n you can write down multiple conditions else if i am writing here what condition n and for this statement n if this is true statement n would be executed right and after that else and here after every condition suppose this is end of conditions after that a default you can say else would be there there we will consider a default statement that would be executed if neither this or nor these conditions are true means um none of this condition is true then this should be executed default statement right and after this if else else if let us see lc flared this is lc flatter right i am writing what suppose statement x see this statement x this is not part of this else if letter this is part of a program so this will be executed if none of the condition is true right so now you can relate this kind of thing so there are what multiple cases you have you are putting multiple conditions based on that some actions would be performed right so i hope you can relate this thing with this else if scenario else if later so now let me draw a flowchart for this thing this is the sequential flow of execution of the program now first we got first condition suppose this condition is true statement one would be executed right and no other conditions would be checked if this first condition is true finally you will get what that to that statement statement x fine suppose this is false condition one is false so now second condition else if means second condition now check the second condition this condition is true then statement 2 would be executed in case this is false then next condition means condition 3 would be checked if this condition is true 2 cases can be there true or false if this is true means statement 3 would be executed in case this is false like this you can check multiple conditions right and after that suppose i am writing here what at last condition n i hope you can see this this is up to condition n and if this is true then statement n would be executed and if this says all this is false condition n is also false the last condition is also false then what would be executed the else block and at the last we have written what default statement in else flow so now that will be executed default statement here ds means default statement right and after this if statement one execute if this two three after execution of statement end or even after the default what statement would be executed statement x because that is part of a program that was not part of this else if letter so ultimately that would be executed statement x over here you can write statement abc or any kind of anything you can write according to your convenience so after each the statement would be executed so now i hope you got the working of this thing using this flowchart the working of lc flat and the condition would be checked always from top to bottom first of all this condition then second and third up to n from top to bottom right as soon as a true condition found that uh statement associated to the true block of that statement would be executed and after that the the control will directly go to the statement x right skipping all the other conditions if this condition is true then directly statement 2 will be executed and control will go here these conditions would not be checked right so now let me discuss it with the help of a program so now let us take this program i want if your marks are greater than 80 it means grade is a your grade is a marks greater than 70 then and less than this 80 then grade is b greater than 60 marks less than 70 then c grade otherwise you will get d grade and finally it will print end of program right so now see when you run this program you will include the header file also then on the output screen it will ask enter marks i am taking here integer but marks would be in float you can take float here and percentage f here right now marks suppose you are entering here 80 now what output you will get see first of all it will check the first condition if marks greater than 80 mark's greater than 80 no marks are 80 only so now it will not execute this thing see i'm not printing i'm not writing any curly braces because because for this if i'm just writing a single statement so no need to write down curly braces if you are printing like printf you entered you have entered percentage d marks and you are printing marks and next time you are printing your grade is a means two lines you are printing or more than one line you are printing then you have to put those statements into curly braces i am not putting any curly braces here right so now it will not go here it will check the second condition if marks greater than 70 marks greater than 70 yes so it will print what b grade see here you can ask this question do you need to write here marks greater than 70 and less than 80 because this would be executed for marks greater than 70 and what less than and equal to 80 no you don't need to write that second condition why because if marks are greater than 80 then ultimately this block would be executed suppose marks are 81 so marks greater than 80 so this block would be executed so the program will skip all the other statements and finally it will print grade is a and after that it will skip all the other conditions and it will directly print end of program because this is not a part of this else if letter right so no need to write down here that is why the second condition it will it will ultimately if marks are greater than 80 it will ultimately check this condition this condition is true and it will print grade a right so now this in this case if 80 then it would be printed now suppose marks i am entering here at 45 first this condition would be checked this is false so it will not enter here second condition would be checked greater than 70 this is false so it will not enter here third condition would be checked greater than 60 this is also false so it will not enter here now finally else block if none of the condition is true then this else block would be executed so finally it will print d grade and after that it will print end of program so if none of the condition is true in that case this else block would be executed and after that whatever the statements that those are not part of this else if letter those would be executed right and if you put here semicolon then it will give error you can check out this thing also right and other than this if you want to put curly braces then that also you can write down like after if you can put curly braces here after else also what how you can write down this else if you can write down simply else right after that else block we will be starting with curly braces after that you can write down this if and marks greater than 70 and here you can print b grade for this if this is opening and this is closing right then within this after this we have another else and again you can start this and this if you can write down like if marks greater than 60 again you can put curly braces c grade you can close curly braces like this you can write down so you can write down here something like this and after that you can write down end of program why i am not writing like this because see if you are checking for this this is what i am printing a single statement so you can remove these curly braces for this else also i'm just printing grade d so you can remove this curly braces right and this if else for this else i am putting these curly braces so for this else if and else within this i am writing if else right fs is considered as a single statement so if single statement then no need to put curly braces so you can remove the curly braces of this else also right now for this else here i am writing within this if one statement so you can remove this and this f and else right this is what a complete one statement this f else so you can remove this curly braces also so you can remove all the curly braces and if you do some formatting then rather than writing something like this you can simply write else and this if here only but you have to put space between these else and if otherwise it will give error right because this is another this is a keyword and this is another keyword that is why i'm not putting any curly braces and i'm simply writing like this right now i hope you got the working of this elsif statement so the one one question for you is or you can say one assignment for you is you have to make a program suppose i am entering a number or anything like i can enter from a to z small letter capital letters and uh 0 to 9 numbers or any special character anything you can enter you have to take input from the user and you have to tell the entered number is the entered thing is uppercase lowercase letter or a number or a that special character how you will check this thing you have to write down this program and you can tell me in comment box you have done or not and if you are finding any difficulty in this program in writing this program then you can ask me in comment box or you can send me after writing a program you can send me that program or that screenshot of that program on my instagram account also right so that's it for this also and see one more thing it's not like that you have to write down this else it is not compulsory to write down this else here you can skip this also but for every else there should be an if uh statement but you can skip else statement so if you don't write this else statement then also you can check what output you will get if you uh enter this 45 this condition is not true this is not true this is not true so this else you are not writing so finally it will print what only end of program it will not print any grade that is also fine uh right so now rather than this else if this thing you can also do with some other control statement that is switch this is also used to check multiple cases so this switch statement i'll be discussing in next video right either you can write down the sales safe or at the place of this elsif you can do this program with help of the switch statement also right so now i'll see you in the next video till then bye take care
Info
Channel: Jenny's Lectures CS IT
Views: 114,257
Rating: undefined out of 5
Keywords: jennys lectures, else if ladder, if else if ladder in c, what is else if ladder in c, else if ladder in c language, else if ladder in c flowchart, if else if ladder, if else if ladder example program in c, else if, if else if ladder syntax, if else if ladder with examples, if else ladder, what is else if ladder in c language, else if in c, if else if, gate cs lectures, best channel to learn programming, best channel to learn C language for beginners, control statements in c
Id: sRCtrviXnLs
Channel Id: undefined
Length: 13min 53sec (833 seconds)
Published: Mon Jan 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.