Menger sponge second iteration and onwards

Hi All,

I have successfully created first iteration of a menger sponge by using this nested loop

for (int x = -1; x < 2; x++) {
    for (int y = -1; y < 2; y++) {
        for (int z = -1; z < 2; z++) {
            int sum = abs(x) + abs(y) + abs(z);
            int r = 100;
            if (sum >1) {
                box.setPosition(x+x*r,y+y*r,z+z*r);
                box.set(100);
                ofSetColor(255/sum, 255/sum, 255/sum);
                box.draw();
            }
        }
    }
}

My question is how would I proceed to second iteration from here?

#ofApp.h

ofBoxPrimitive box;

Thanks in advance