To make it work, you have to make the complete array available inside the loop. That means you cannot use an indexing tunnel at the exit to construct the array. Instead, you have to use a shift register and build array inside the loop.
This will do what you want. It would have been easier to show you if you'd posted your code.