Advertisement



< Prev
Next >



C# Nested if Statement





The general principle of the nested-if decision-making statement is that, 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:





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.

//C# Example of nested if statement 

using System;

class NestedIfEx
{

public static void Main()
{
	int a = 99, b = 100, c = 101;
	if(a<b)
	{
		if(a<c)  // This is a nested if 
		Console.WriteLine("{0} is less than {1} & {0} is also less than {2}", a, b, c );
	}
	else 
		Console.WriteLine("{0} is not less than {1}", a, b);
		
}
}


Output


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




Please share this article -





< Prev
Next >
< C# Else If Statement
C# While 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