How to achieve a repeat function that can be stopped

Very likely can be done. What determines the "conditions"?
Paul