Is it a good practise to perform certain operations in your code based on the count value obtained from a complicated for loop? For example, lets say there are four objects you want to compare in your for loop, and based on the results of the comparison a certain count variable is incremented. And based on the value of count the code proceeds with performing different operations.
Is this a normal/good practise? Can you guys suggest something better?
Are you using the count value to check for condition to exit the loop? If so I suppose it depends on how certain you are that the comparasions you talk about are certain to drive the count to satisfy exit condition. I would built in some sort of guard in the event things don't go as you plan.
Not sure if this is what you're talking about, but this is stupid:
1 2 3 4 5 6 7 8 9
for( int i = 0; i < 5; ++i ) {
switch( i ) {
case 0: /* do something */ break;
case 1: /* do something else */ break;
case 2: /* do something different */ break;
case 3: /* do something wild and crazy */ break;
case 4: /* do something totally different */ break;
}
}