Advertisement



< Prev
Next >



Nested if-else Statement




In nested if-else decision-making statement, an if-else statement is nested inside an if statement, hence this program control structure 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(optionally declared) part is executed and the nested if-else statement is not executed at all.

  • 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.




    Advertisement




    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 but it is not less than 98




    Please share this article -





    < Prev
    Next >
    < Nested If Statement
    Switch Statement>



    Advertisement

    Please Subscribe

    Please subscribe to our social media channels for daily updates.


    Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




    Advertisement



    Notifications



    Please check our latest addition

    C#, PYTHON and DJANGO


    Advertisement