In my case, I needed to run through an array of 20,000 elements and check for a number of true conditions and make changes which could affect cells already examined in the loop, making them true. I needed to keep checking the array until all conditions were false.
Based on your required algorithm, you don't need Loops (at least not directly), what you need is Recursion. Which means, you need one Function, which will have that algorithm to check all 20k items, find all/any found=true, make the changes you want, let it affect others, and then within that function call the same function (call itself) again. Technically, it should keep looping recursively, function within a function calling itself. Yeah, like the movie inception, except, you will keep calling the function only if found = true.
Which means, let's say in the 500th recursion, if all the found = false, it won't repeat anymore.