I have a contrived example to demonstrate the request for a specific functionality - I wonder if anyone has a clever trick to do this.
The following is a problem one
[In many ways this question should be closed as it's opinion based.]
This problem crops up often. I always opt for a solution that minimises the instructions in the iterative part.
{ /*don't pollute the outer scope with ii*/
int ii;
for (ii = 0; ii < 3; ++ii/*I've always preferred this to ii++*/) {
printf("%d ", ii);
}
printf("%d\n", ii);
}
Ternaries, if statements etc. just obfuscate things. In my opinion.