Switching pattern with button

Hi!
I am very new at programming and have a hopefully simple question.
I have put together a project with 5 LEDs and want to program patterns for how they behave, to change between patterns I want to use a simple tactile button. The problem is that I can only change pattern with the button between flash sequences.

As I have programmed it now I use:

void loop (){
int button = digitalRead(2);
  if (button == 1){
    j= j+1;
  delay(500);
  if (j >= 4){
  j=1;
  }

Is there a way to read the button value all the time and not just when the program loops that bit of code in the beginning of my program?

(Sorry for my English)

int pinArray[] = {3, 5, 6, 9, 10};   //Analog outputs
int count = 0;                       //counter of positions in matrix pinArray[]
int timer = 0;                       //Delay between blinks
int pot = A0;                        //potentiometer value on analog input #0
int brightness = 100;                //LED-Brightness
int j = 0;

void setup(){                        
  pinMode(2, INPUT);                 // Setup pin 2 as input
  for (count=0;count<=4;count++) {   // Setup all pins in pinArray[] as outputs
  pinMode(pinArray[count],OUTPUT);
}
}
void loop (){
  int button = digitalRead(2);
  if (button == 1){
    j= j+1;
  delay(500);
  if (j >= 4){
  j=1;
  }
  }
  
  if (j==1){                          //Program 1 - Flowing lights
  blink1(i);
 } 
 
  if (j==2){                          //Program 2 - Shut off all LED's
  for (count=0;count<=4;count++) {
  analogWrite(pinArray[count],0);
}
  }
  if (j==3){                          //Program 3 - All LED's at brightness value
  for (count=0;count<=4;count++) {
  analogWrite(pinArray[count],brightness);
}
  }
}

Read a button state with Interrupt:
http://arduino.cc/en/Reference/AttachInterrupt

Thanks! Works flawlessly now! :slight_smile: