Defining Multiple Pins At Once

Hi,
I wanted to know is there a way to define several pins as OUPUT or INPUT with one command?
something like:

pinMode(pin[1,2,3,4,5,6], OUTPUT);

there's lots of topics about this but they're all from 2011, 2012 and 2014-_- I thought things should have been changed since then

I used the following to initialise a large number of buttons which I put in an array. I was using an mcp23017 hence the mcp.pinMode etc

void initialiseButtons () {
  Serial.println("initialising buttons...");
  for (uint8_t i = 0; i < numButtons; i++) { //for each button
    mcp.pinMode (buttonPin[i], INPUT);       // set as input
    mcp.pullUp (buttonPin[i], HIGH);         // set as high

    Serial.print("button ");                 //print button i initialised
    Serial.print(i);
    Serial.println(" initialised");
  }
}

Change to something like this

#define numPins             9   //number of pins attached
uint8_t Pin[16]  = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};//array of pins

void initialisePins () {
  Serial.println("initialising pins...");
  for (uint8_t i = 0; i < numPins; i++) { //for each pin
    pinMode (Pin[i], OUTPUT);       // set as output
    

    Serial.print("pin");                 //print pin i initialised
    Serial.print(i);
    Serial.println(" initialised");
  }
}

Of course it is better to change the names to suit the input rather than just calling them pins hence my own code with buttonPins etc. You can adjust the pins in the array so they dont have to be in 1,2,3,4 order you could have 2,1,4,5,10 for example

Much of the code is debugging etc so equates to

#define numPins             9   //number of pins attached
uint8_t Pin[16]  = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};//array of pins

void initialisePins () {
  for (uint8_t i = 0; i < numPins; i++) { //for each pin
    pinMode (Pin[i], OUTPUT);       // set as output
  }
}

The array is not necessary if the pins are just 1,2,3,4,5 etc it could just be a for loop

  for (uint8_t i = 0; i < 10; i++) { //for each pin
    pinMode (i , OUTPUT);       // set as output
  }

very cool way, thanks a lot

With port manipulation you can usually do this with a single statement, although the code may be less portable and you'll need to get comfortable working with binary constants and masks.