Assume we have a following code:
switch (currentChar) {
case 'G':
case 'T':
case 'M':
case ';':
case '\r':
case '\n':
doSomething();
break;
}
If the first condition is met (currentChar == 'G'
) are the following cases also compared, or the program jumps straight to doSomething()
?
What would be faster to execute: the switch-case, or an if with ||
operator?
Clarification:
I want doSomething
to be executed if any of the conditions is met. I also know that the 'G' case will occur in some 99% of all cases. Can I assume that it will be compared as the first if I put it on top of the list?