# Marching squares: Finding multiple contours within one source field?

Principally, this is a follow-up-question to a problem from a few weeks ago, even though this is about the algorithm in general without application to my actual problem.

The algorithm basically searches through all lines in the picture, starting from the top left of it, until it finds a pixel that is a border. In pseudo-C++:

int start = 0;
for(int i=0; i<amount_of_pixels; ++i)
{
if(pixels[i] == border)
{
start = i;
break;
}
}


When it finds one, it starts the marching squares algorithm and finds the contour to whatever object the pixel belongs to.

Let's say I have something like this:

Where everything except the color white is a border.

And have found the contour points of the first blob:

For the general algorithm it's over. It found a contour and has done its job. How can I move on to the other two blobs to find their contours as well?