Using JavaScript Nested Loops


In this blog I am going to explain the use of nested for loops in JavaScript.

<html xmlns=''>
    <title>Nested loops in JavaScript</title>
    <script type='text/javascript'>
        var i, j, mulTot;
        for (i = 1; i <= 15; i++) {
            for (j = 1; j < 15; j++) {
                mulTot = i * j;
                if (mulTot < 10) {
                    mulTot = ' ' + mulTot;
                else {
                    mulTot = ' ' + mulTot;


Nested loops are used in most of the places it is used in Matrix multiplication,  Displaying tables and many other places. In this example first the outer loop is initialized and if the condition  is true it will give control to the inner loop and this inner loop will keep on incrementing till the condition of the inner loop is true and when the condition of the inner loop becomes false then only the control will be transferred to the outer loop.


Through this blog we came to know about how to use multiple loops in our program.

Last updated:9/18/2014 1:24:06 PM


Leave Comment