It seems to me there is a much easier solution for your problem, since all numbers are known at the beginning (see attached example , LabVIEW 7.1):
Your attached code only does your outer loop and my example does the same. Simply calculate the number of averging runs needed and use a FOR loop (For simplicity, I assume the total number of images is an integer power of two and thus divisible by the number of averages without remainder).
These are just some rought ideas, modify as needed. Good luck!