You can’t. You need to rethink your approach. Unroll the “loop” concept and make each iteration distinct. Open the next container in response to the action you’re expecting in the current container.
It runs with what Tim H suggested - create your containers in a sort of linked-list organization
Pseudo code:
Open Container 1
Next container is 2
previous container is Nil
Get user input
Open Next Container passing 3 (next) and 1 (previous)
Increment next and previous as you go so you always know what’s next and where you came from in case you need to go backwards.