When a loop runs inside another loop called the nested loop(inner loop). The first loop is called the outer loop and the second loop is called the inner loop.
The outer loop always executes first, and then the inner loop executes inside the outer loop. If the outer loop executes once, then the inner or nested loop will execute the full which means the nested loop will run until the condition meets.
const arr = [1, 2, 3];const arr1 = [4, 5, 6];for (let i = 0; i < arr.length; i++) {for (let j = 0; j < arr1.length; j++) {console.log(arr[i], arr1[j]);}}
Here is the example above, if the outer for loop runs once, then the inner loop or nested loop will run 3 times.
Post a Comment