As you can see the result of the if statements is not dependand on the for loop and are known prior to the loop. I need to make sure the code runs as fast as possible. I can have my if statements outside of the loop and have several different for loops like this
This is messy and can get a lot more messier if I need to add another level of decision making.
My question basically is if java compiler will optimize the first code snippet not do the the logic branching for each loop iteration which will make the first code snippet to be as efficient as the second code snippet. I know that I can run some tests to check on this but I would like to find out for sure and that it is documented somewhere. I purposely ommit the information about our jdk version because I would like to find out the generic answer or the one that shows the differences between different compilers.