Actually this problem is not with your loop or the business logic you're defining for your application. Instead in these frameworks that you're using there is only one thread-ed application which performs all of the logical executions and also makes the UI responsive. So, as long as those loops are running the UI thread won't be able to execute, making all of the UI (including buttons, TextBoxes) frozen.
What you need here, is to execute those loops in any other thread, which would run in the background. Thread can be an example of such process that can be executed in the background. You can use this to run the code in background (asynchronously) to let your application stay responsiveness (able to recieve clicks on Button, TextBox etc).
I have written another answer to depict the same condition and problem. You might be interested in reading that answer of mine. Do give this a read:
How to safley give my function without making my main form stuck[
^]
Once the UI is responsive, you can click on the button to terminate the loop using,
break
if you want to break the loop only, or stop the thread itself etc. It depends on your need.