Turning program on and off using sinlge push button

The program below sweeps through frequencies 1hz to 6 hz and then back to 1hz. I've been trying to incororate code to use a push buttom to turn the arduino on and off.
I have seen programs that turn an LED on and off but am having difficulty incororating them into this program.
I'm not a software engineer so would be very grateful for any help

uint8_t freq_Hz[6] ={1,2,3,4,5,6};// Set up an array for the 6 frequencies 
uint8_t pulses =25;              // Number of pulses per frequecncy
uint8_t  duty =10;                // Sets Duty cycle
unsigned long period_ms;
unsigned long OnTime;
 int out_pin=4;
 int out_pin1 =3;
 int Led1=8;
 int Led2=9;
void setup() {
  // put your setup code here, to run once:
{
  pinMode(out_pin,OUTPUT);
  pinMode(out_pin1, OUTPUT);
  pinMode(Led1,OUTPUT);
  pinMode(Led2,OUTPUT);
}
}
void loop()

  // put your main code here, to run repeatedly:
  {
  for (uint8_t i=0;i<6;++i){                      //Cycle through the 6 elements of freq_hz array
  period_ms =1000/freq_Hz[i];                     // Calculate the period in ms of freq_hz
  OnTime = (period_ms*duty)/100;                 // Calculate from % duty cycle ON Time in ms
   
for(uint8_t j=0; j<pulses;++j){              // loops frequency x pulses at each frequency
digitalWrite (out_pin,HIGH);
digitalWrite (out_pin1,HIGH);
digitalWrite (Led1,HIGH);
digitalWrite (Led2,HIGH);
delay(OnTime);
digitalWrite(out_pin,LOW);
digitalWrite(out_pin1,LOW);
digitalWrite(Led1,LOW);
digitalWrite(Led2,LOW);
delay(period_ms - OnTime); 
}
  }
  }

If you turn off the Arduino by pressing a button how could it react to a further button press ?

I suspect that what you mean is that you want to run a portion of your code or not depending whether of not a button has become pressed. If so, then look at the StateChangeDetection example in the IDE and use the principle to change the state of a boolean variable from true to false and vice versa on alternate button presses. Use the value of the boolean variable to control which portion(s) of your code run

First, press Ctrl+T in the IDE. Looks better, doesn't it?

Next, because you use delay() it's hard to react on a button press directly. You need to change it to use millis() if you want to be able to react to the button immediately.

To detect a button press, have a look at the state change example. Or grab a library like Bounce2.

Now simply remember (in a variable) if you want the program to run or not. And toggle that when you see a button press.

Example with a blinking led:

#include <Bounce2.h>

const byte LedPin =  LED_BUILTIN;
const byte ButtonPin = 10;
const unsigned long BlinkInterval = 1000;

Bounce button;
bool blinking = false;

unsigned long blinkMillis;

void setup() {
  button.attach(ButtonPin, INPUT_PULLUP);
  pinMode(LedPin, OUTPUT);
}

void loop() {
  //button press toggles blinking on or off
  button.update();
  if(button.fell()){
    blinking = !blinking;
  }

  //only blink if 'blinking' is true
  if(blinking){
    if(millis() - blinkMillis >= BlinkInterval){
      blinkMillis = millis();
      digitalWrite(LedPin, !digitalRead(LedPin));
    }
  }
}