Advertisement



< Prev
Next >



C ++ Nested If Else Statement




Another important decision-making statement of C++ language is nested if-else, in which 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 part(optionally declared) 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.




    Advertisement





    //* nested if-else example */
    
    
    #include<iostream>
    
    using namespace std;
    int main()
    {
    
    if('a'<'b')
    {
    	if(9>8)
    	 	cout<<"a is less than b and 9 is greater than 8";
    	else
    		cout<<"a is less than b and 9 is less than 8";
    }
    else 
    	cout<<"a is not less than b";
    	
    return 0;
    }
    


    Output


    a is less than b and 9 is greater than 8

    In the latter program, we have compared values in char variables, internally their ASCII values have been compared to find out which character has a greater ASCII value.



    Please share this article -





    < Prev
    Next >
    < Nested If Statement
    For Loop>



    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