Another option is to use a capacitor as a hardware denounce.
if you don't want/need to interrupt the code that is run when a button is pressed, you can simply run your long code in the loop.
If you do want to be able to interrupt your lengthy code while it is running, you could use interrupts on the button. A interrupt triggers a bit of code when, for example, you press the button and that chnages the digital port status.