Advertisement



< Prev
Next >



Nested if Statement





In nested-if decision making statement, an if statement is nested inside another if statement, hence this control structure is named nested if.

The statement connected to the nested if statement is only executed when -: Note: There could be an optional else statement associated with the outer if statement, which is only executed when the condition of the outer if statement is evaluated to be false and in this case, the condition of nested if condition won't be checked at all.




Advertisement




Nested if example


So let us see an example of nested if statement and we are also going to associate an optional else statement with the outer if statement, which may only execute if the condition of outer if statement is evaluated to be false.

// nested if statement 

public class NestedIf
{

public static void main(String... ar)
{
if(99<100)
{
	if(99<101)  // This is a nested if 
	System.out.println("99 is less than 100 & 99 is also less than 101");
}

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 -





< Prev
Next >
< Else-If Statement
Nested If-Else 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

PYTHON and DJANGO


Advertisement