In this type of statement the if block contains another if block within it. And the inner if statement is executed only if the outer if statement’s condition is true.
The syntax of the nested if statement in C#:
1 2 3 4 5 6 7 8 | if(condition1) { //block of code to be executed if(condition2) { //block of code to be executed } } |
nested if statement Flowchart:

Example of nested if statement in C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using System; namespace DecisionStatement { class NestedIfStatement { static void Main(string[] args) { int a = 300; int b = 600; /*check the boolean condition */ if (a > 100) { Console.WriteLine("This is outer if statement"); if (b > 200) Console.WriteLine("a is greater than 100 and b is greater than 200"); } } } } |
Output:
1 2 | This is outer if statement a is greater than 100 and b is greater than 200 |