There may be other ways, don't really use sub-programs but you could always wrap the whole thing in an if statement with the condition that you want to monitor. If you check the box on the set-up of the if to "Check Expression Continuously" it will monitor that condition and if it changes will exit the if statement. If you have motion you will want to add an else and put a stopj() command in there, I usually use stopj(8) but depending on what you are doing, may need a faster stop deceleration than that, the number is in radians per second per second.
How can I exit a subprogram early based on some condition?