I have many functions which require searching through images, i.e.

Code:
for(y = 0; y < h; y++) {
  for(x = 0; x < w; x++) {
    do_whatever(x, y);
  }
}
I would like to do something cleaner, like:

int max = w * h;
int count = 0;

Code:
while(count < max) {
  int y = count / w;
  int x = count % w;  
  do_whatever(x, y);
  count++;
}
(Assume the / and % are replaced with fast methods, such as shifts...)

Is there a better way, performance is important since each pixel is visited seperately.

I'm mainly only trying to clean up my code before my project gets too large. The nested loops are too deep. Thanks,

-Joe