How to make a while loop run alongside other code

How do you make a while loop run alongside the rest of your code so the UI still works and everything else works. I have a hunch that you make a new swift file but am not sure if it needs any other code

i suggest not using a while/for loop if you want it to run infinitely as it will eat up your processor since it doesnt run on an interval (imagine a hundred or more runs per second)

use swift timers instead

What is the point of the whole loop running???

Why is it going to run so long?