if...else lets you run different code paths depending on a condition. It's essential for decisions like login success/failure, pass/fail grading, or checking whether something is in stock.
cpp
#include <iostream>
using namespace std;
int main() {
int mark = 75;
if (mark >= 80) {
cout << "Excellent";
} else if (mark >= 40) {
cout << "Pass";
} else {
cout << "Fail";
}
return 0;
}The program checks conditions from top to bottom. mark >= 80 is false, so it moves to the next condition, and since mark >= 40 is true, it prints Pass.
You should see
PassInfo
Condition order matters. Checking the widest range first and narrowing down as you go is usually the clearest approach.