looping error

  • sometimes when I press the button nothing happens

You've said nothing about how the switch is wired. Could be any number of reasons. Like, for instance nothing happens during those delay()s.

It's silly to be worried about bounce when you have a minimum of half a second delay between switch reads. No switch bounces that long. If one did, the 0.03 second delay wouldn't take care of it.