Nested if..else Statement


  • You can combine multiple if / if-else /if-else-if ladders when a series of decisions are involved.
  • So you can make sure that your program executes certain instructions when a series of conditions are met.

Syntax:


if(Boolean_expression 1)
{
//Executes when the Boolean expression 1 is true;
}
if(Boolean_expression 2)
{
//Executes when the Boolean expression 2 is true
}
//Statements which will be executed always

    

Example:

public class Test
{
   public static void main(String args[])
   {
       int x = 30;
       int y = 10;

       if( x == 30 )
       {
           if( y == 10 )
           {
           System.out.print("X = 30 and Y = 10");
           }
       }
   }
}
   


Output:
X = 30 and Y = 10
Since both the if conditions are true, the program prints "X = 30 and Y = 10".

.


Popular posts from this blog

Naming Conventions

if..else..if Loader