एक का प्रयोग करें यदि या अन्य यदि कथन किसी अन्य के अंदर है या अन्यथा यदि कथन है। नेस्टेड इफ स्टेटमेंट का सिंटैक्स इस प्रकार है -
if( boolean_expression 1) {
/* Executes when the boolean expression 1 is true */
if(boolean_expression 2) {
/* Executes when the boolean expression 2 is true */
}
} निम्नलिखित एक उदाहरण है जो सी # में नेस्टेड इफ स्टेटमेंट के उपयोग को दर्शाता है। यहाँ, हमारे पास दो if स्टेटमेंट हैं जो दो स्थितियों की जाँच करते हैं।
if (a == 5) {
/* if condition is true then check the following */
if (b == 10) {
/* if condition is true then print the following */
Console.WriteLine("Value of a is 5 and b is 10");
}
} यहाँ पूरा उदाहरण है।
उदाहरण
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
//* local variable definition */
int a = 5;
int b = 10;
/* check the boolean condition */
if (a == 5) {
/* if condition is true then check the following */
if (b == 10) {
/* if condition is true then print the following */
Console.WriteLine("Value of a is 5 and b is 10");
}
}
Console.WriteLine("Exact value of a is : {0}", a);
Console.WriteLine("Exact value of b is : {0}", b);
Console.ReadLine();
}
}
} आउटपुट
Value of a is 5 and b is 10 Exact value of a is : 5 Exact value of b is : 10