Maintain outer scope in two for loops?

Here’s the trick you’re looking for: