It works for me, but perhaps I don't quite understand what you want to do. Try adding some code so you can see the LED responds to the switch press.
void setup()
{
pinMode(pin, OUTPUT);
pinMode(ledPin, OUTPUT); // sets the digital pin as output
int swPin = 8;
pinMode(swPin, INPUT);
digitalWrite(swPin, HIGH); // turn on pull-up resistor
digitalWrite(ledPin,HIGH); // turn on the LED so you know the code is waiting for the switch
while(digitalRead(swPin) == HIGH)
; // do nothing while the switch is not pressed
// code will get will get here when swPin is switched to ground, so the LED will turn off
digitalWrite(ledPin, LOW);
}