trying to loop a specific function

//what I am trying to do is when relay1 is turned on it will loop

analogWrite(led, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);

//forever so something like this

void Relay1On() {
Serial.print("Switch Relay 1 turn on ...");

//then loop the rest of this code

void loop(){

analogWrite(led, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

}

//How could I do this

Please read How to use this forum, specifically section 7 how to post code.

void Relay1On() {
    Serial.print("Switch Relay 1 turn on ...");
   

//then loop the rest of this code

void loop(){
...
...
}
}

That's not going to work; you can not implement a function inside a function.

loop() is your main function; you do everything from there.

Your code could look something like

void loop()
{
  if (digitalRead(relayPin) == HIGH)
  {
    analogWrite(led, brightness);

    // change the brightness for next time through the loop:
    brightness = brightness + fadeAmount;

    // reverse the direction of the fading at the ends of the fade:
    if (brightness <= 0 || brightness >= 255)
    {
      fadeAmount = -fadeAmount;
    }
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
}

Not perfect code, but just to give you the idea. How you switch the relay on (an possibly off) is up to you.