Question: ahk how to break a loop?
Answer: Use a global variable (keepCycling) and toggle it to break the loop. Global variables should be declared in the beginning of a script. Adding a global variable might be the easiest solution for your case since your loop takes a while to complete.