 In Java, you can put if statements inside of if statements, and that's called a nested if. Here's a program that asks for a price and quantity, and calculates the subtotal, the tax, and the total, and prints them out. Let's run it. If I have a unit price of $4.50, and I order 7 items, there's my subtotal, tax, and total. I'd like to be sure that both the price and quantity are greater than zero. Let's add an if-else for the price. After I get the price, I want to ask if the price is greater than zero. If that's the case, it's okay to do all these things. I could indent all the statements by hand, one by one, but my integrated development environment gives me a helping hand. If I highlight all the lines and press Tab, it indents them all for me. And I can close the if block by inserting a closing brace. I'll need an else block, in case the price is not greater than zero, to print out the message that the price must be greater than zero. And I'll put the closing brace on that block as well. Let's recompile, and when I run again, if I enter a price of $-4.95, the program will immediately tell me that the price must be greater than zero. That handles negative prices. But what happens if I give negative quantities? If I give a valid unit price, a positive number, and a negative quantity, it still goes through with that bad calculation. So I need another if else to handle that. After I get the quantity, I have to ask if the quantity is greater than zero. If it is, then it's okay to do all of my calculations. And again, I'll press Tab to do the indent, and close my block. Otherwise, if the quantity is not greater than zero, I'll print the message that says, the quantity must be greater than zero, and close that block. I have an if in lines 19 through 28 inside of another if from lines 15 through 31. That's a nested if compile, and run the program with a valid unit price and a valid quantity, and everything works nicely. With an invalid price, I get an error right away. And with a valid price and an invalid quantity, I get an error message telling me that my quantity must be greater than zero. The program is now working the way I want it to, because I have a nested condition, an if within an if. Is it possible to have an if statement inside the else portion? Yes, it is. Here's another way I could have written the invoice program. In this program, I'm asking for both the price and the quantity before I do any of my if statements. Then I ask, is the price greater than zero and the quantity greater than zero? If both of them are true, then it's okay to do my calculation and output. Otherwise, either the price is less than or equal to zero or the quantity is less than or equal to zero. In the else portion, I'm going to nest two one-way if statements. If the price is less than or equal to zero, I give an error message. Then I check to see if the quantity is less than or equal to zero. If that's the case, I give an error message to that effect. There's no else needed for either the if in line 27 or the if in line 30, because the only way I can get there is if the price is less than or equal to zero or the quantity is less than or equal to zero. If they were both greater than zero, I would have handled it here in lines 20 through 25. Let's run this program with valid input first. I'll have an item price of 450 and order 10 of them. Everything works great. If my unit price is negative and my quantity is okay, I'm told that the price must be greater than zero. If my unit price is valid but my quantity is negative, I'm told that the quantity must be greater than zero. And if I enter a negative price and a negative quantity, I'm told that both of them are not valid. There's an important point here. In order to do a good test of my program, I have to test all the combinations of good and bad input to make sure I've covered all the cases. Another thing to notice is the difference between this program and the preceding one. In the first version of the program, as soon as I got an error, I gave the error message. In this program, I wait until I have all the input before I give any of the error messages. Which approach is better? That's a design decision. The takeaway from this video is that it's possible to have an if nested inside of an if or to have an if nested inside of an else. If the design of the program requires it, you can nest ifs and elses inside of one another as deeply as you need to to get the effect you need.