How do I do this program?

The IDE is also jam-packed with useful worked examples, like how to detect when a switch becomes closed, as opposed to detecting when it is closed.