How do I do this program?

Or since the requirement is to wait for the switch, do that once in setup().