Post

@CodeRed_dev if (numCases <= 2)
{
if (...) {}
}
else
{
switch (...) { ... }
}
English

@CodeRed_dev if is the goat, you cant beat it
English

@CodeRed_dev You forgot OOP (virtual functions in place of if/switch)
English

@CodeRed_dev Nahh come on! No one uses switch ☠️☠️☠️
English

@CodeRed_dev I love switch statements, they look so nice and organized 😂
English

@CodeRed_dev Both are great and have their own use case.
Sword or bow?
BOTH!
English


@CodeRed_dev that's like asking if you should use a rake or bush trimmer for garden work.
you use 'if' either if there's only one arm, you're checking multiple different things, or when there are multiple arms with different checks.
You use switch one variable is checked for many conditions.
English

@CodeRed_dev Both. 'Switch' for enums, multiple choices or conditions; 'If' for single condition.
I'm not using 'Switch' to check whether toggle is on or off, and I don't use 'If' to check what state my character is in.
English

@CodeRed_dev If there's less than like 4 paths, if statement. Anything more and it's a switch case
English

@CodeRed_dev I voted "if" because I tend to use them more often, but "switch" is also good for certain features too
English

@CodeRed_dev When there is only one condition that needs to be checked (for example, if an object belongs to a certain class), I go for switch cases.
In case of multiple conditional checks within the same line, the traditional if-else is what I follow.
English

@CodeRed_dev string weaponType = "Throwable Gernade"
if(weaponType == "Throwable Gernade"){
//do throwable gernade things
} if(weaponType == "Normal Gernade"){
//do normal gernade things
} if(weaponType == "Axe Murderer Gernade"){
//do normal axe murderer gernade things
}
//etc.
English

@CodeRed_dev It's not an either or question. Some cases lend themselves to switch, others require an if or two.
English












