*Note*: My apologies for the volume being somewhat screwed up, Starcraft II turned up microphone boost on its own. This gets fixed in a few videos.

Topics Discussed: The structure behind using nested if statements effectively and how easy it is to get them confused!

Source Code for Lesson 7:

import java.util.Scanner;
class Jtutorial1 {
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        //pay -- double
        System.out.println("Enter a double: ");
        double pay = input.nextDouble();
        if (pay <1000){
            System.out.println("Pay is less than 1000.");
            if(pay >= 1000 && pay <1200){//  ||-or  &&- and
                System.out.println("Pay is less than 1200, And greater than 1000");
                if(pay >= 1200 && pay <1500){
                    System.out.println("Pay is less than 1500, And greater than 1200");
                    if(pay >= 1500){
                    System.out.println("Pay is greater than 1500");
    } //End main
} //End class

Nested if structure
In this video I give you a fairly simple example as to why we should avoid nested if statements whenever we possibly can. The primary reason behind this is because they syntax is overwhelming, and it simply becomes very difficult to read / understand.

The syntax of a nested if is exactly the same as a normal if / else statement, except that it takes place in the ‘payload’ of an existing if / else statement.

There isn’t really too much to write up about this lesson, as it built off of what we covered in the lesson before now. Just watch your syntax and you should be able to grasp this almost immediately.

Last modified: April 8, 2019