it's better a solution like this
switch(number)
{ case 0:
case 1:
case 2:
}
...or with if...else if... else if??
thanks a lot!!
it's better a solution like this
switch(number)
{ case 0:
case 1:
case 2:
}
...or with if...else if... else if??
thanks a lot!!
Hello,
For my personal opinion, switch-case has a better performance but I haven't investigated more about this topic.
Regards,
Kui
You will probably get a slight improvement out of the switch-case statement, but it's not going to be too noticeable unless you do it very very often. On the other side of the coin, the repetitive "if (x==whatever)" statements will JAR up smaller when compiled due to the repeating pattern of code.
Hi all.
I personally would not suggest to use a series of If/else-if statements instead of "switch-case" to optimize your code. Most of times the "switch" statement is slightly faster (even if your data types are automatically promoted to ints) especially if the numbers are close together (uses a fast direct lookup).
Moreover I would not sacrifice the readability and the "constrains" of a good switch statement in most cases (gameStatus, level, ...) and I keep using if-else where the statements are more complex.
I've frankly always found that substitution a messy hassle.
regards
davide
<AtomicTag.com/>