top of page

Nested if Statement क्या है?

  • Writer: Siddharth Sharma
    Siddharth Sharma
  • Oct 7, 2025
  • 1 min read

Nested if statement में एक if statement के अंदर दूसरी if statement होती है। यानी, एक condition के true होने पर ही दूसरी condition को चेक किया जाता है। ऐसा multi-level decision making के लिए किया जाता है।


Syntax:

if (condition1) {
  // condition1 true होने पर यह code चलेगा
  if (condition2) {
    // अगर दोनों condition1 और condition2 true हैं तो यह code चलेगा
  } else {
    // condition1 true है लेकिन condition2 false है
  }
} else {
  // condition1 false है
}

Example:

int age = 20;
int isCitizen = 1; // 1 means true, 0 means false

if (age >= 18) {
  printf("Old enough to vote.\n");
  if (isCitizen) {
    printf("And you are a citizen, so you can vote!");
  } else {
    printf("But you must be a citizen to vote.");
  }
} else {
  printf("Not old enough to vote.");
}

इस program में पहले age check किया गया, सही होने पर citizenship check होती है।


flow char of nested if
flow char of nested if

उपयोग:

  • Multi-level decisions handle करने के लिए।

  • एक condition के अंदर ही दूसरी condition लगाकर logical dependencies दर्शाने के लिए।


सावधानी:

  • Nested if statements ज्यादा गहरे हो जाएं तो code पढ़ना और समझना मुश्किल हो सकता है।

  • इसलिए nested if का प्रयोग सीमित और स्पष्ट होना चाहिए।

Nested if statements complex decision-making के लिए powerful टूल हैं, जो प्रोग्राम को hierarchical तरीके से नियंत्रित करते हैं.

 
 
 

Comments


bottom of page