button program issue

Recently I have loaded the Button program found under File->Examples->Digital->Button. Here is me issue:

when i connect a cable to pin #2, EVEN IF I HAVE THE OTHER END DANGLING IN THE AIR, it will always turn the light on… why? there is no power going to pin #2, yet it acts as though there is… why?

please help.

You have what is effectively a wire antenna attached to the pin. It can pick up all sorts of signals from the air and might read anything. Connect it to something and it will behave normally.

And if you had set that pin as pinMode(INPUT_PULLUP) then you would have specifically told it to read HIGH if it doesn't see a clear low.