Simple loop code for SmartApp

I am writing a simple SmartApp to blink a Hue bulb a user configurable number of times when a contact sensor experiences an Open event. The concept is blink the light when our little one opens her bedroom door when she should be sleeping. I am new to groovy and am a sysadmin so the depth of my programming experience is limited to PowerShell. I had hoped something this simple could be cobbled together but the looping of on and off of the bulb proves difficult. Any help would be appreciated…even if its just to point me at an existing SmartApp with a loop that I can copy. Thanks.

Take a look at the smartapp called flashify. (or the flasher? I forget the actual name now) - “the flasher”. It should be in the shared smartapps. (sorry for all the edits.)