How to stop the code loop and start it again?

Suggest you look at this thread.

Some of the items will not apply to what you want, others should help you a lot.