One time execution of a variable incrementation
See http://www.gammon.com.au/switches.

Basically you need to detect the transition between the switch not being pressed before, and now being pressed. This transition will occur once per press (possibly after you add debouncing). If you just test for the switch pressed naturally you will get multiple increments.




  Assuming I add debouncing, how would it help in incrementing the value of ncycles only once ?


To clarify, you increment once on a transition, note when you did this (eg, by calling millis() ) and then ignore any further transitions for, say 10 ms.