When I turn off the lamp above my Arduino, 1 loop of sketch is run.

I've just been tinkering with the first couple of projects in the Arduino starter kit, and decided to turn the lamp above the Arduino off so that I could see the lights flashing in the dark.

To my surprise when I did this, one loop of the following program (a modification of Project 2) was run.

// global variables
int switchstate = 0;

//setup
void setup(){
  // outputs 
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);

  // inputs   
  pinMode(2,INPUT);
}

void loop(){

  // read value of pin 2
  // either HIGH or LOW
  switchstate = digitalRead(2);

  // if the button is not pressed
  if (switchstate == LOW) {
    digitalWrite(3, LOW); // turn the green LED on pin 3 on
    digitalWrite(4, LOW);  // turn the red LED on pin 4 off
    digitalWrite(5, LOW);  // turn the red LED on pin 5 off
  }
  // if the button is pressed
  else {
    digitalWrite(3, HIGH);
    delay(250);
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
    delay(250);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    delay(250);
    digitalWrite(5, LOW); 
  }
}

Later, as I was writing this post, when I turned the lamp on, it occured again.

What could be possibly causing this?

Heat from the lamp above the Arduino?

I think this is some electrical noise between the source of your arduino and the source of the lamp (Arduino powered by pc, and pc connected to AC plug right?

Possible solution: How about debouncing the button?