LED state

Hi everyone ! :)

i have created a simple program to change the state of an LED using a switch. it worked but not at all.

I just want to know why not working properly? Thanks !

int sw=4; int led=5; int st=0;

void setup(){

pinMode(sw,INPUT); pinMode(led,OUTPUT);

}

void loop(){

if(digitalRead(sw)==HIGH){ st=~st; } while(digitalRead(sw)==HIGH){}

digitalWrite(led,st); }

Got a pull-down resistor on your switch? How are things wired? What do you mean by "don't work." What did you want to happen? What actually happened?