In article <f1468$48722d2a$>,
says...
> hi there,
>
> suppose I want to iterate for a specific variable e.g. i , but for non
> regular (or consecutive) values. For example i=0,1,2,4,5,7,8 etc
> how can I do that with a for loop?
>
> MY solution which is not that elegant involves if statements (or switch
> statements) in the body of the loop: e.g.
>
>
> for (int i=0; i<=8; i++)
I'd probably do something like this:
int f(int i) {
if (i==3 || i==6)
return i+2;
return i+1;
}
for (int i=0; i<max; i=f(i))
// whatever
of course, I've only defined f to do exactly what you showed, skipping 3
and 6, but nothing else. If you really meant (for example) to skip all
multiples of three, that's somewhat simpler. In any case, it's purely a
matter of figuring out what you want and writing 'f' to suit.
--
Later,
Jerry.
The universe is a figment of its own imagination.