I want to call methods inside a loop until a condition is met ( reps >= 1000) and then jump outside of the loop and test which method was more efficient, then jump back into the old method and ignore the method call that was least efficient. Is this possible? Here is my sample code:
// Set the number of times each method is called
public void setReps(String target, String[] sa, long reps) {
shuffleArray(sa); // Shuffle the order of Strings in array
for (int i = 0; i < reps; i++) {
linearStringSearch(target, sa);
backwardLinearStringSearch(target, sa);
counter(); // counts winner
if (reps >= 1000)
chooseAlgorithm(target, sa);
}
So for the above code, I will be testing linearStringSearch() and backwardLinearStringSearch() to see which is more efficient after 1000 loops and then I want to jump back in and ignore either linearStringSearch() or backwardLinearStringSearch() based on the result. I could write a new loop in the chooseAlgorithm() method but I'd prefer to jump back into the old one if possible.