I sometimes find myself in a situation where I have to put some kind of conditional execution in a deeply nested loop, but the actual condition doesn't change during the loop, so the same path of execution will occur each time, like this:
a = something;
for (...)
{
for (...)
{
for (...)
{
// big chunk of code here
if (a == 5)
{
// some code
}
else if (a == 7)
{
// some other code
}
else
{
// some third code
}
// another big chunk of code here
}
}
}
In this situation I feel like putting the conditions outside of the loop statements, but then I have several copies of those "big chunks of code". That makes it a pain to maintain the code, because any change has to go in several places.
I could also imagine placing a call to a function pointer in the inner loop. That pointer could be set outside of the loops. It would however introduce the overhead of a function call in the inner loop. Bad idea?
Maybe the deeply nested switch statement is not a problem on the 68060, due to branch prediction?
Cheers