Programming में Control Statements का इस्तेमाल decision लेने के लिए किया जाता है। जब हमें program के flow को किसी condition के आधार पर control करना होता है, तब हम if
, else
, switch
जैसे control statements का use करते हैं।
Control Statements वो commands होती हैं जिनकी मदद से हम program के execution flow को control कर सकते हैं – यानी कौन सा block चलेगा और कौन नहीं।
इनका use तब किया जाता है जब:
if (condition) {
// code block
}
int age = 20;
if (age >= 18) {
printf("You are eligible to vote.");
}
Explanation: यदि age 18 या उससे ज़्यादा है, तो message print होगा – वरना कुछ नहीं होगा।
if (condition) {
// true block
} else {
// false block
}
int marks = 40;
if (marks >= 50) {
printf("Pass");
} else {
printf("Fail");
}
if (condition1) {
// block 1
} else if (condition2) {
// block 2
} else {
// default block
}
int num = 0;
if (num > 0) {
printf("Positive number");
} else if (num < 0) {
printf("Negative number");
} else {
printf("Zero");
}
जब हमारे पास multiple fixed options हों (जैसे menu selection), तब switch
बहुत useful होता है।
switch (expression) {
case value1:
// code
break;
case value2:
// code
break;
default:
// default code
}
int choice = 2;
switch (choice) {
case 1:
printf("Option 1 selected");
break;
case 2:
printf("Option 2 selected");
break;
default:
printf("Invalid option");
}
Control Statements जैसे if
, else
, else if
, और switch
decision making के लिए बहुत जरूरी होते हैं।
if
flexible होता है और conditions check करता हैswitch
structured होता है और multiple values को handle करता हैControl Statements = Powerful Programming Logic ✅