Terminate the process of simulation automatically?

Hi all,
I am looking for an example of how to automate the simulation process in grasshopper since we have reached the desired target?

Thanks for your help in advance.
Regards