I wish to know how this would impact my coding when handling large volumes of data, and how I would construct my logic arguments
Two questions:
1) What are the main differences between IF-ELSE and Select CASE? Does select case operate by evaluating all cases at the same time?
If I have a situation where, by nature of its construction, need to fulfill two or more cases at the same time, for e.g.
int = 5
Select case int
Case >0
Case 5
Case <0
Where I would need to "trigger" both Cases "1" and "2" for action, do I use CASE over IF ELSE?
2) Now for the other case, if I have a variable that will trigger more one case but I would like to restrict to only one case by priority, say I would only like Case "1" for action and exclude the rest, am I right to say that IF-ELSE would triumph in this regard?
EDIT - I realized that my question was phrased poorly. I did some edits to the code
If-Else and Switch statement are good in different cases.
For example, If-Else has logic conditions like:
and nested constructions like
You cannot do this in switch statement.
However, switch is better, more elegant and faster in some situations:
would look very bad in if-else format:
I'm not sure about your case but in most languages
switch
statement is more performant.Simply said, use switch statement every time it is possible and there are more than two cases. If there are only two cases or it is impossible to use switch - use
if
.