turning led on or off using switch

int inPin = 2;         // the number of the input pin
int outPin = 13;       // the number of the output pin

int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
{
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);
}

void loop()
{
  reading = digitalRead(inPin);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();    
  }

  digitalWrite(outPin, state);

  previous = reading;
}

in above program particularly this step(the code below) is confusing.can anyone explaining it clearly?

long time = 0;         
long debounce = 200;
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();    
  }

  digitalWrite(outPin, state);

  previous = reading;

Grab paper and pencil, and work through it yourself - you'll understand it much better.

The reason it is there is because mechanical switches don't go from ON to OFF (or vice versa) "instantly" like a logic signal, but may flap around between ON and OFF for a few tens of milliseconds, before settling.

int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

Try renaming these to currReading and prevReading. I think you'll see that the code will make (a lot) more sense.