I'm not 100% sure how java handles these two instructions at the machine level, but in all 3GLs I've worked with If/Else is faster than a For-loop or something similar. You should probably still use the For-loop however, since the speedloss is very marginal and readability and maintainability are much better.
Originally posted by Maarten Vergouwen: I'm not 100% sure how java handles these two instructions at the machine level, but in all 3GLs I've worked with If/Else is faster than a For-loop or something similar.
Yeah, but with Hotspot the for loop could actually be faster, as the more often some code gets executed, the more it will get optimized...
This really is an apples vs. oranges comparison, I think. Loops and if/else statements do completely different things, and the speed of each one is very much dependent on what you do inside each of these constructs, which we have no information about. Can you show an example of what the code you're comparing would look like? What are you trying to do? If you're thinking about having 200 if / else if statements, there's often a better way, say by using a switch statement, or doing some sort of lookup in an array, HashMap, or TreeMap. If you show a bit more of what you're doing, we can give better info on how this might work.