đĒ if-else if Ladder in C
đ§Ē Short Explanation:
The if-else if ladder checks multiple conditions one by one. The first true condition runs its block and skips the rest. If none match, the else block runs (optional).
✅ Syntax
if (condition1) {
// block 1
} else if (condition2) {
// block 2
} else if (condition3) {
// block 3
} else {
// default block
}
đ Example
#include <stdio.h>
int main() {
int score = 75;
if (score >= 90) {
printf("Grade A\\n");
} else if (score >= 80) {
printf("Grade B\\n");
} else if (score >= 70) {
printf("Grade C\\n");
} else {
printf("Grade D\\n");
}
return 0;
}
đ§ Output: Grade C
đĄ Common Use Cases
- Grading systems
- Tax calculation slabs
- Menu or user input logic
⚠️ Tips & Mistakes to Avoid
- Ensure conditions are in correct order (most specific to least)
- Don't forget to use curly braces
{ } - Only the first true condition runs
đ Summary
The if-else if ladder is useful when you need to test several possible conditions. It improves code readability and logic flow in programs.
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ