Controlling LED light using a limit switch

No, that is correct. By setting LOW on the output pin, the LED will be powered on.

So I just read through the code in order. It starts by recording the state of the switch. Then...

  1. If the switch is pressed and the status is 0 (off) then turn the LED on and set status to 0.

  2. If the switch is not pressed and the status is 0 then turn it off and set status to 1.

  3. If the switch is pressed and the status is 1 (on) then turn it off and set status to 1.

  4. If the switch is not pressed and the status is 1 then turn it on and set status to 0.

So if the switch isn't pressed, 2 and 4 will blink it on and off. If it is pressed then 1 turns it on repeatedly. Unless you pressed it while it was on, then 3 turns it off repeatedly.

I hope the logical changes are obvious?