MCAWALA

C++ Vertical Menu

C++ Programming Topics

Control Statements in Programming – If और Switch का आसान हिंदी में इस्तेमाल

Programming में Control Statements का इस्तेमाल decision लेने के लिए किया जाता है। जब हमें program के flow को किसी condition के आधार पर control करना होता है, तब हम if, else, switch जैसे control statements का use करते हैं।

Control Statements क्या होते हैं?

Control Statements वो commands होती हैं जिनकी मदद से हम program के execution flow को control कर सकते हैं – यानी कौन सा block चलेगा और कौन नहीं।

इनका use तब किया जाता है जब:

  • किसी condition पर decision लेना हो
  • कुछ code selectively run करना हो
  • Program की logic को manage करना हो

✅ If Statement

🔹 Syntax:

if (condition) {
  // code block
}

🔹 Example:

int age = 20;
if (age >= 18) {
  printf("You are eligible to vote.");
}

Explanation: यदि age 18 या उससे ज़्यादा है, तो message print होगा – वरना कुछ नहीं होगा।

✅ If-Else Statement

🔹 Syntax:

if (condition) {
  // true block
} else {
  // false block
}

🔹 Example:

int marks = 40;
if (marks >= 50) {
  printf("Pass");
} else {
  printf("Fail");
}

✅ Else If Ladder

🔹 Syntax:

if (condition1) {
  // block 1
} else if (condition2) {
  // block 2
} else {
  // default block
}

🔹 Example:

int num = 0;
if (num > 0) {
  printf("Positive number");
} else if (num < 0) {
  printf("Negative number");
} else {
  printf("Zero");
}

🔀 Switch Statement

जब हमारे पास multiple fixed options हों (जैसे menu selection), तब switch बहुत useful होता है।

🔹 Syntax:

switch (expression) {
  case value1:
    // code
    break;
  case value2:
    // code
    break;
  default:
    // default code
}

🔹 Example:

int choice = 2;
switch (choice) {
  case 1:
    printf("Option 1 selected");
    break;
  case 2:
    printf("Option 2 selected");
    break;
  default:
    printf("Invalid option");
}

🔚 निष्कर्ष (Conclusion)

Control Statements जैसे if, else, else if, और switch decision making के लिए बहुत जरूरी होते हैं।

  • if flexible होता है और conditions check करता है
  • switch structured होता है और multiple values को handle करता है
  • Beginner से लेकर expert तक हर developer को इनका सही use आना चाहिए

Control Statements = Powerful Programming Logic