arduino control of relays

hello I wonder if someone could help
i want to switch a 4 relay board on off easy enough with push button control [done] but what I cant seem to get my head around is to switch 1+2 on/off together the same time while button A pressed NOT LATCHED only switched while button pressed and to switch button B controlling relays 3/4 together
BUT THEY MUST NEVER BE ON AT THE SAME TIME
i have managed to get 1/2 to work but my code is really messy i have ordered a dummy’s manual but hope someone could help thanks in advance

[code]


// clockwise/counter clockwise relay 
// set relay board pins arduino pins



#define relay3 9
#define relay2 8
#define relay1 7

 const int buttonPin = 5;  // the number of the pushbutton pin 

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status


//#define cw 5;  // clockwise switch
//#define ccw 4; // counter clockwise switch


void setup(){
  
//set arduino pins high state to avoid switch at power up
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);

delay (500);
// initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);


pinMode(7, OUTPUT-LOW);// set relay state to off?
pinMode(8, OUTPUT-LOW);
pinMode(9, OUTPUT-LOW);

pinMode(5, INPUT_PULLUP);//this pin to gnd to take low?
//pinMode(5, INPUT_PULLUP);//this pin to gnd to take low cw/ccw?



}

void loop() {//relay test below commented out
 /* digitalWrite(relay1, LOW);
  delay (1000);
  digitalWrite(relay1, HIGH);
   delay (1000);
 digitalWrite(relay2, LOW);
  delay (1000);
  digitalWrite(relay2, HIGH);
   delay (1000);

digitalWrite(relay3, LOW);
  delay (1000);
  digitalWrite(relay3, HIGH);
   delay (1000);
*/
 // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn relay on:
    digitalWrite(relay1, HIGH);
     digitalWrite(relay2, HIGH);
  } else {
    // turn relay off:
    digitalWrite(relay1, LOW);
    digitalWrite(relay2, LOW);
 

  }
}

[/code]

You need a pair of boolean variables, pairAOn and pairBOn, initialized to false.

When the A switch is pressed:

  buttonStateA = digitalRead(buttonPinA);
  if(buttonStateA == HIGH)
  {
     if(!pairBOn)
     {
        digitalWrite the first relay on
        digitalWrite the second relay on
        pairAOn = true;
    }
  }
  else
  {
        digitalWrite the first relay off
        digitalWrite the second relay off
        pairAOn = false;
  }

Do something similar for the B switch and relays 3 and 4.