I would say unrolling the loop would be the most obvious way out of this one:
uint8_t i = 0;
for ( i = 0; i < 32; i++ )
{
printf("Instance of loop %d\n", (8*i)+0);
printf("Instance of loop %d\n", (8*i)+1);
printf("Instance of loop %d\n", (8*i)+2);
printf("Instance of loop %d\n", (8*i)+3);
printf("Instance of loop %d\n", (8*i)+4);
printf("Instance of loop %d\n", (8*i)+5);
printf("Instance of loop %d\n", (8*i)+6);
printf("Instance of loop %d\n", (8*i)+7);
}
In theory, this should also be quicker, since you have fewer tests and jumps. You could unroll more severely than this too, if needed.
You may also be interested in Duff's device (SO question explaining it), which would allow you to unroll any sized loop, not just one with nice factors. There are of course limits as it requires you store in memory the count of what you need, which in this case exceeds the 8-bit field, but, for the purposes of looping, say 137 times, it would come in useful.
Note you don't need to do the 8*i+1
stages, that's just to verify that enough events have happened.
Another note: "but I don't want to write my code 8 times!" can be overcome with the use of inline
functions (C99) or macros (C89) as necessary.