![else if matlab else if matlab](https://static.javatpoint.com/tutorial/matlab/images/matlab-if-elseif-else-end-statement.png)
However we would need to use more than one logical expression to find out what letter grade that we have received and this leads us to the else if conditional statement. So for example it may be more desirable to show the letter grade that we have received in the course. Now while this is much more desirable than just using an if statement alone what if we want to have more than one logical expression. So right now we have a grade of 55 input into our program, so let’s run the program and we see that it does say fail and so this program is working correctly. So now the program has two different paths to take based on this logical expression and if it evaluates as true or false. So the purpose of using the else statement is to add a second path that the program can take and this ends up being really easy to implement, so right now we have if the grade is greater than or equal to 60 then we want to display pass or else if that logical expression is not true then we want to display fail and that’s actually it.
![else if matlab else if matlab](https://i.ytimg.com/vi/wev4yaRqPi4/maxresdefault.jpg)
So let’s return to MATLAB and revise our program to implement the else statement. So since that is false our second statement group is evaluated in the program ends. Now in this case we start off with a grade again and we are trying to determine if we have passed or failed a class, so we evaluate this input based on our logical expression and in this instance our grade of 55 is not greater than or equal to 60. So now let’s look at our flowchart that we’re going to implement in MATLAB. Now unlike the if statement if this logical expression is false a second statement group can be evaluated before the program ends. So again we start our program with an input and evaluate that input with a logical expression and if true statement group 1 is evaluated and the program ends. So this leads us to the else statement so here is the structure and a flowchart of the else statement Now hopefully you can see here that one of the major limitations of the if statement by itself is that we only have one path that the program can take it would probably be preferable to have the program tell us that we have failed the class rather than just ending and not really displaying anything for us.
![else if matlab else if matlab](https://i.ytimg.com/vi/hBjVoMjTGz8/hqdefault.jpg)
So since the grade was not greater than or equal to 60 the program just ended. Let’s say 55 and now we have run the program and you can see here that nothing happens and that’s because there’s only one path that the program can take to actually evaluate a statement. Now let’s go back up and change this input grade to something less than 60. So I click run and we get pass and that is what I would expect because my grade was greater than or equal to 60. So let’s run the program and see what we get here output to the command window. In this case I will choose let’s say 70 then I will add a semicolon on the end of this line to suppress the output and next we will move to implementing our if statement, so we say if our grade is greater than or equal to 60 this is our logical expression and the greater than or equal to is our relational operator. So in the grade variable we are going to assign it a value and you can assign it anything that you would like. So we are start off our program by entering a numeric grade and we are going to store it in a variable called grade because that just makes sense. So let’s go over to MATLAB now and implement this. In this example 65 and if this grade is greater than or equal to 60, if that is true we will know we have passed the class and the program will end.
![else if matlab else if matlab](https://fiverr-res.cloudinary.com/images/q_auto,f_auto/gigs/193887778/original/fe3c7de68d6d43073d120671f3c95a682649931b/matlab-problem-like-matlab-livecsript-simulink-simscape.jpg)
So here is a flowchart of the example that we are going to work in MATLAB and in this case what we are trying to do is take an input grade. However if this logical expression is false the program will just end. Such as less than, greater than or equal to and if this logical expression evaluates is true then the program will execute one or more statements and then end.