---
title: "Using JavaScript Nested Loops"  
description: "Introduction  In this blog I am going to explain the use of nested for loops in JavaScript.   html xmlns=\"http://www.w3.org/1999/xhtml\"  head  Nested"  
author: "Danish Khan"  
published: 2012-11-09  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/390/using-javascript-nested-loops  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Using JavaScript Nested Loops

[Introduction](https://www.mindstick.com/articles/13122/an-introduction-to-network-cables)\

In this [blog](https://www.mindstick.com/articles/12705/myths-and-misconception-about-blog) I am going to [explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) the use of [nested](https://www.mindstick.com/forum/45/itemcommand-event-in-nested-repeater-and-listview) for [loops](https://www.mindstick.com/forum/161927/explain-the-python-while-loops-with-example) in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript). \

```
<html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>Nested loops in JavaScript</title></head><body>    <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;                }                document.write(mulTot);            }            document.write("<BR>");        }     </script></body></html>
```

##### Output:

![Using JavaScript Nested Loops](https://www.mindstick.com/blogs/76595753-9cee-4ce9-b46f-555b27daff8f/images/063ea633-06ea-4af4-9438-aec8434c8561.jpg)

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.

##### Conclusion:

Through this blog we came to know about how to use multiple loops in our program.\

---

Original Source: https://www.mindstick.com/blog/390/using-javascript-nested-loops

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
