Nested for loops

Understand how to handle nested for loops.

We'll cover the following

Introduction

A nested loop has one loop inside another. When a loop is nested inside another loop, the inner loop runs many times inside the outer loop. In each iteration of the outer loop, the inner loop will be restarted. The inner loop must finish all of its iterations before the outer loop can continue to its next iteration.

For example, the outer loop iterates 55 times, and the inner loop iterates 66 times when run independently. This means that the inner loop will iterate for a total of 3030 times.

⚙️ Note: A statement execution count indicates the number of times a statement is executed by the program.

This concept is a little challenging to grasp at the start. Let’s start the coding to get a better understanding.

Get hands-on with 1200+ tech skills courses.