< Prev
Next >



Nested if-else Statement




In nested if-else decision making statement, an if-else statement is nested inside an outer if statement, hence it is named nested if-else.




Working of nested if-else


  • If the condition of outer if statement is false then the statement connected to its else part is executed and nested if-else is not executed.

  • The statement connected to the if of the nested if-else is only executed when -: If condition of this nested if is false then the statement with its connected else is executed.






    Nested if-else example


    //nested if-else example
    
    public class NestedIfElse
    {
    
    public static void main(String... ar)
    {
    
    if(99<100)
    {
    	if(99<98)
    		System.out.println("99 is less than 100 & 99 is also less than 101");
    	else
    		System.out.println("99 is less than 100 but 99 is not less than 98";
    }
    
    else 
    	System.out.println("99 is not less than 100");
    
    }
    
    }
    


    Output


    99 is less than 100 & 99 is also less than 101




    Please share this article -

    Facebook Google Pinterest Reddit Tumblr Twitter




    < Prev
    Next >
    < Nested If Statement
    Switch Statement>
    Please subscribe our social media channels for notifications, we post a new article everyday.

    Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

    Coming Next
    -
    C++ and Python

    Ad2