C # nested if statements
In C #,nested if-else statement is legal, which means you can use another iforelse ifstatement in aniforelse ifstatement.
grammar
C #nested if statements syntax:
if (boolean_expression 1) { / * When a Boolean expression is true execution * / if (boolean_expression 2) { / * When the Boolean expression 2 is true execution * / } }
You can nestelse if ... else, manner similar to nestedifstatements.
Examples
using System; namespace DecisionMaking { class Program { static void Main (string [] args) { // Local variable * Definitions * / int a = 100; int b = 200; / * * Check boolean condition / if (a == 100) { / * If the condition is true, check the following conditions * / if (b == 200) { / * If the condition is true, the output following statement * / Console.WriteLine ( "a value of 100, and b values are 200"); } } Console.WriteLine ( "a precise value is {0}", a); Console.WriteLine ( "b the exact value is {0}", b); Console.ReadLine (); } } }
When the above code is compiled and executed, it produces the following results:
a value of 100, and the value of b is 200 a precise value of 100 a precise value is 200