Program dose not loop

I copy this program from OddWire.com Arduino tutorials/Digital/button. It is to turn on and off a led. as far as I can tell the program loops until the button is pressed then stops.

by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Try changing
pinMode(buttonPin, INPUT);
to
pinMode(buttonPin, INPUT_PULLUP);

How is your switch wired?
loop() will loop over and over again.
.

Change made no difference. Same program as is in Arduino tutorial. Wired 5VDC to switch, switch to10K resister and Pin 2, other side of resister to pin 13.

Read Mr. Gammon's discussion here:

Also see this image, R3 and SW3

Here is a pic of the wiring.

OK I have egg on my face. I wire to pin 13 instead of ground. When I post the picture I saw my problem.

Thanks

I read your post good reading.

did I tell you I hate the 5 min. rule for posting.

Egg is a good source of protein. :wink:
.

did I tell you I hate the 5 min. rule for posting.

It goes away when you have a few posts under your belt. It is to stop spammers posting lots of posts.

Read about input switches here:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html