Using button to end loop

I am trying to have a button which, once pushed and held still, immediately stops the board from what its doing and instead makes it do something else. The code below is the only method that I came up with. But the only problem i see is that the code below would behave too slowly. Is there some method out of this? I'm using a pull-up resistor, the same setup in here:

void loop() {
  val = digitalRead(inPin);
  if(val== HIGH){
 //does something else
  }else{
while(....){
//takes considerable time for this loop to finish approx 5 seconds
}
}

Thanks!

If you don't know about interrupts have a look at this http://arduino.cc/en/Reference/AttachInterrupt. You can code your interrupt to detect the button press (may need to account for button boucing though so it doesn't call the interrupt over and over while it's bouncing, and interrrupts don't like delays() FYI-so millis), and then in the body of your interrupt function (the curly braces part {}) you can tell it to do something else. A simple switch case statement has worked well for me in this type of need...so the Arduino is always "listening" for the interrupt and when you press the button it goes to your interrupt service routine (ISR), goes to the swicth case statement and selects the other function you want it to go to immediately.

Here's what I'm using. I do happen to use a RF remote so that's why the RISING, just substitute that out for the one used for your button.

attachInterrupt(1, modeSelector, RISING);  //button on pin 3

The actual ISR:

void modeSelector() {
  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();
  // If interrupts come faster than 100ms, assume it's a bounce and ignore
  if (interrupt_time - last_interrupt_time > 100) {
    
    switch (lightMode) {
      case 0: lightMode = 1;
      break;
      case 1: lightMode = 2;
      break;
      case 2: lightMode = 3;
      break;
      case 3: lightMode = 4;
      break;
      case 4: lightMode = 5;
      break;
      case 5: lightMode = 6;
      break;
      case 6: lightMode = 7;
      break;
      case 7: lightMode = 8;
      break;
      case 8: lightMode = 9;
      break;
      case 9: lightMode = 10;
      break;
      case 10: lightMode = 11;
      break;
      case 11: lightMode = 0;
      break;
      default: lightMode = 0;
    }
  }    
    last_interrupt_time = interrupt_time;
 }

This should give you a good start.