Understanding Nested For Loops

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. 😜

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Leecode 122. Best Time to Buy and Sell Stock II (C,C++,C#,JAVA,JAVASCRIPT,TYPESCRIPT,RUBY)

How to Automatically Configure OpenVPN Clients to Resolve AWS Private Hosted Zone Records

Print characters at prime indices

Oracle WebLogic Server — Remote debugging with eclipse

How to Migrate WooCommerce to Alibaba Cloud ECS with Let’s Encrypt

Hand-over update and new impulse

An unacknowledged use of Hash Tables

Run Jenkins in k8s

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Elle D

Elle D

More from Medium

Chapter 07- Inheritance And Polymorphism.

In the torrid afternoons of summer, I sit by my window and think of the rain.

Pedal in a Bubble

Blue Ocean Day 2