trouble with toggling a loop on/off

struggling with piece of code here...

i'm trying to make a pushbutton toggle a loop on/off.

When the loop is running, some LEDs should blink in turn (in a loop) and when it's off, just one of them should emit light.

I'm at the point where i get them to blink in turn when i push the button, but they run through the sequence just once and then return to "off" (where just one of them are on).

const int redpin = 2;
const int greenpin = 3;
const int yellowpin = 4;
const int bluepin = 5;
const int buttonPin = 6;
int buttonState = 0;

void setup()
{
pinMode(redpin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(yellowpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
digitalWrite(redpin,HIGH);
delay(500);
digitalWrite(redpin,LOW);
delay(100);
digitalWrite(greenpin,HIGH);
delay(500);
digitalWrite(greenpin,LOW);
delay(100);
digitalWrite(yellowpin,HIGH);
delay(500);
digitalWrite(yellowpin,LOW);
delay(100);
digitalWrite(bluepin,HIGH);
delay(500);
digitalWrite(bluepin,LOW);
delay(100);

}
else
{
digitalWrite(redpin,HIGH);
}
}

I'm at the point where i get them to blink in turn when i push the button, but they run through the sequence just once and then return to "off" (where just one of them are on).

Which one is on?

If you release the switch, the state changes to LOW (if you have the switch wired properly). If you want the blinking to continue, you need to look at the state change detection example, and determine when the switch becomes pressed once, twice, three times, etc.

Each time, you toggle the value of a flag (blinking, not blinking, blinking, etc.).

Independently, you blink the LED if blinking is true, or light the one LED if blinking is false.

Totally untested so you may have to do a bit of debugging. But this should work.

const int buttonPin = 6;
void setup()
{ 
}

bool blinking=false;
unsigned long lastPress=0;
void loop()
{
if ( (digitalRead(buttonPin)==HIGH)&&
     ((micros()-lastPress) >400 ) )
    {lastPress=micros();
     blinking=!blinking;
    }
doBlink();
}

void doBlink()
{
int led;
unsigned long t=micros()%2000;
int activeLed=int(t/500) + 2;

for(led=2;led<6;led++)
  {
   if((led==activeLed)&& blinking)   
     digitalWrite(led,HIGH);
   else
     digitalWrite(led,LOW);
  }
}