interrupting a task while it is in prosess. even if its using a delay

Ok so i dont have a good code to explain what i want, but it is really simple so here we go;

i have 4 buttons, and a 3x3 LED display witch uses 9 pins. total 13 pins with the buttons.
the task is to make a 4 LIGHTSHOWS, and you can swich between each lightshow by pressing a button. i can swich between the lightshows, but that means i have to run a "test" after every delay, and use several short delays with a test in between each of them instead of a long delay.
no matter how i do it, the lightshow WONT swich before the current lightshow is compleated. i want to be able to INTERRUPT the lightshow, and start another one. also if posible, not having to hold the button for at least 100ms witch is not much.

i have attempted to use noInterrupts and interrupts, but dont really get how that works. made everything a total mess.
tried to use break; but i cant use that properly cause i have to use an if inside a while statement, and i cant break the while statement with that if.

here is a code, but it is NOT compleated. its just what i got so far. nothing is properly set up.

int A=0;
int TEST()
{ 

  if (digitalRead(Btn[0]) == HIGH)
  { 
    A = 1;
  }

  if (digitalRead(Btn[1]) == HIGH)
  { 
    A = 2;
  }

  if (digitalRead(Btn[2]) == HIGH)
  { 
    A = 3;
  }

  if (digitalRead(Btn[3]) == HIGH)
  {
    A = 4;
  }
  delay(100);
}

int LedReset()
{
  for (int n = 0; n <= 8; n++)
  {
    digitalWrite(Led[n], LOW);
  }
}


// ** * ****** * **



/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/


void loop(){
  TEST();

  while(A == 1)
  {
    digitalWrite(Led[0], HIGH);
    TEST();
    digitalWrite(Led[0], LOW);
    TEST();

  }
  while(A == 2)
  {
    digitalWrite(Led[1], HIGH);
    TEST();
    digitalWrite(Led[1], LOW);
    TEST();

  }
  while(A == 3)
  {
    digitalWrite(Led[2], HIGH);
    TEST();
    digitalWrite(Led[2], LOW);
    TEST();

  }
  while(A == 4)
  {
    digitalWrite(Led[3], HIGH);
    TEST();
    digitalWrite(Led[3], LOW);
    TEST();

  }
}

you might want to notice how i use the "TEST();"

does anyone have a tips for what i could do? if you use advanced code, please explain it.

thank you guys a lot.

Look at the BlinkWithoutDelay example in the IDE.

It notes the time an action started by reading the value from millis() then checks each time through loop() to see whether the required time period has elapsed. If so it stops the action. If not it goes round again and could do other things such as reading an input and reacting to it, perhaps by setting a variable that, when checked, terminates the current action.

Reading up on state machines would also be helpful as your program is in one of several states at any one time. Using millis() timing with a state machine is a good match, as is the use of switch/case based on the current state.

I am sure that you realise that the code you posted does not compile.

Forget you ever heard the term "interrupt".
Forget you ever saw the function "delay()".

I wrote an extended demo of the BWOD concept in the first post in this Thread. It may give you some ideas.

...R