How to write a digitalWrite array for MCP23017 expander chip?
Use a variable ( iterator) and count from 0 to 8 (excluding):

void setup() 
{
    mcp.begin(0);
    mcp1.begin(1);

    for (uint8 pin = 0; pin  &lt; 8; pin ++)
    {
        mcp .pinMode(pin, OUTPUT);
        mcp1.pinMode(pin, OUTPUT);
    }
}

void loop() 
{
    for (uint8 pin = 0; pin &lt; 8; pin++)
    {
        mcp .digitalWrite(pin, LOW); 
        mcp1.digitalWrite(pin, LOW); 
    }
}


If the order in which the digital pins are written to LOW matters than split them like in your example, (however, I do not think that is the case).

void loop() 
{
    for (uint8 pin = 0; pin &lt; 8; pin++)
    {
        mcp .digitalWrite(pin, LOW); 
    }

    for (pin = 0; pin &lt; 8; pin++)
    {
        mcp1.digitalWrite(pin, LOW); 
    }
}


Note : for clarity I would call the mcp variables mcp1 and mcp2 instead of mcp resp mcp2, or an even more intuitive name if there is a clear function for both mcp's.

Using uint8 creates an unsigned byte instead of an int which saves also one byte of stack memory.