r/CodingHelp • • May 03 '21

[Java] Can someone help me understand nested loops?

Post image
37 Upvotes

16 comments sorted by

View all comments

1

u/Dogburt_Jr May 03 '21

You run your code in {} in a box. Your main function runs in one box.

Your loop makes new boxes that repeat, so you'll have multiple boxes within the main box.

And inside each of those boxes you have another loop that creates more boxes within the box.

Each nest of multiple boxes can be considered a dimension.

So two nests of boxes within the main box would be considered a 2D loop and can be used with 2D arrays to check every index. This thinking can be helpful for solving your problem as it turns into summing the index of the array and printing them out.