Both if-else and switch let you branch, but they fit different situations.
Use if-else when your conditions involve ranges (x > 10), multiple variables (a > b), or complex boolean expressions. if-else can test anything that produces a boolean.
Use switch when you compare one variable against a set of known constant values. Checking a menu choice, matching a command string, or mapping a month number to a name are all good fits for switch.
// Better as if-else: range check
if (score >= 90) { grade = "A"; }
else if (score >= 80) { grade = "B"; }
// Better as switch: exact value match
switch (menuOption) {
case 1 -> placeOrder();
case 2 -> checkStatus();
case 3 -> exit();
}
A good rule of thumb: if you're writing + else if blocks that all compare the same variable with ==, a switch will be cleaner.