Can this Code be Shorter?

Hi all,
Anyone can help me on making this part of a PushButtons Code shorter? Some other similar codes are used in the same code. So, if shortening this part is possible, it would apply to the others as well.

Your help would be appreciated!

  {
  reading2 = digitalRead(inPin2);
if (reading2 == HIGH && previous2 == LOW && millis() - time > debounce) 
{
state2 = !state2; // Toggle the state
pressCount1++;
time = millis();
switch(pressCount1%4)
 {
      case 0:
digitalWrite(outPin1, LOW);
digitalWrite(outPin2, LOW);
digitalWrite(outPin3, LOW);
digitalWrite(outPin4, LOW);
digitalWrite(outPin5, LOW);
digitalWrite(outPin6, LOW);
digitalWrite(outPin7, LOW);
digitalWrite(outPin8, LOW);
delay(100);
digitalWrite(outPin1, HIGH);        // Turn on  pin1
        break;
      case 1:
digitalWrite(outPin1, LOW);        // Turn off  pin1
        break;
      case 2:
digitalWrite(outPin1, LOW);
digitalWrite(outPin2, LOW);
digitalWrite(outPin3, LOW);
digitalWrite(outPin4, LOW);
digitalWrite(outPin5, LOW);
digitalWrite(outPin6, LOW);
digitalWrite(outPin7, LOW);
digitalWrite(outPin8, LOW);
delay(100);
digitalWrite(outPin2, HIGH);        // Turn on  pin2
        break;
      case 3:
digitalWrite(outPin2, LOW);        // Turn off  pin2
        break;
    }
  }
  previous2 = reading2;
  }

Shorter...
What is your aim - more efficient code, less flash required to do the same function, or just shorter so there isnt as much to read...?
Do you want it 'complex' but short, or long and readable...

Just curious on shorter

I'd use a 'for loop' for switching the pins high and low.

for (int c2 =1; c2 <= 8; c2++){
      digitalWrite(c2, LOW);
    };

Shorter so there isnt as much to read is my aim. The less complex the better, though.

I'd use a 'for loop' for switching the pins high and low.

That might be shorter to read, but a smart compiler will unroll that for loop and generate the same code as originally posted anyway.

Cheers,

but a smart compiler will unroll that for loop and generate the same code as originally posted anyway.

No this is not always the case. It depends on how the compilers optimisation has been set up. The the case of embedded processors where code space is at a premium I wouldn't expect any unrolling to take place.

The for loop is the way to go but in the code that pluggy posted this will only work if you have consecutive pins to use.
To make this universal define an array with the pin numbers in them and index the array in the loop:-

// in setup()
pinArray[0] = 4;  // first pin to use is pin  4
pinArray[1] = 7;  // second pin to use is pin  7
pinArray[2] = 12;  // third pin to use is pin  12
// an so on until all the pins have been defined

// then the code:-

for (int c2 =0; c2 <= 8; c2++){
      digitalWrite(pinArray[c2], LOW);
    };

Also since the code is repeated, put it in a function!

void setPinsLow() {

for (int c2 =1; c2 <= 8; c2++){
      digitalWrite(c2, LOW);
    };

}