Understanding Nested For Loops

Elle D
2 min readMar 15, 2021

--

Constantly practicing algorithms helps build your muscle memory on how to solve problems effectively. It really comes down to this: As a Software Engineer or Computer Programmer, we are giving many tools(loops, arrays, methods, etc). It’s our job to learn which tools will best help us solve the problem. I recently had a challenge that required me to create a multiplication table. The catch was that this table has to be returned as a 2D array that contained arrays of integers that make up a multiplication table from 1x1 to NxN.

Admittedly I had quite a bit of trouble solving this at first. I gave it my best shot and came up with a solution that wasn’t quite right😩 . I ended up finding the solution which called for me to use a for loop to solve a problem. When I saw the solution, I felt like I was in the movie Inception!

Now before you judge me, clarify by saying this wasn’t just ANY ol’ for loop, it was a NESTED FOR LOOP!

Solution to the problem using a nested for loop

In an effort to better understand this conundrum, I began to play around with nested for loops. The more I tried different ways of using them the more it made sense to me.

Here is a 5 min. video explanation of my understanding of a nested for loop.

Hopefully ,this short clip helps demystifies the nested for loop.Until next time…Happy Coding Ya’ll. 😜

--

--

Elle D
Elle D

No responses yet