How to use nested loop in HTML and JavaScript

                 How to use a nested loop in HTML

calendar in html

In this tutorial, we are make to demonstrate how to use a nested loop in HTML and Javascript to create a beautiful calendar design. I hope you will learn something from this code.

A nested loop is a loop within the loop, the loop is a two-dimension inner loop, and the outer loop .inner loop is nested inside the outer loop. 

How does the loop work? 

 First, we are initial the value that the value first passes to the outer loop triggers the inner loop which executes the process. and then the second pass of the outer loop triggers the inner loop again and again till the statement to an end.

  for( var i= 0 ;i<10;i++){
for(var j=0;j<10;j++){
  //something else

<title>Nested Loop in HTML</title>
<h1 style="text-align: center;"> DEMO</h1>
<ul class="weekdays">
<div id="days"></div>
<div class="bottom"></div>

The first loop is usually called the outer loop. and then runs the outer loop and inner loop up to 10 times each .inner loop execute the individual digits while the outer loop call, again and again, determines how many times the task is repeated.

For Example : If you're reading a book and book file line by line and for each line should be count how many times the line is in there till the end of the statement.

      list-style-type: none;
      margin: 0 auto;
      padding: 10px 0;

.weekdays li 
      display: inline-block;
      width: 13.6%;
      color: #fff;
      text-align: center;
      padding:10px 0;
      margin:0 auto;
      color: #777;
      background: #1abc9c;
      color: white !important
      background-color: #009688;
    margin-bottom: 30px;

A Nested loop using HTML and javascript creates a beautiful calendar design and displays it below. how the calendar looks like and you have copied the code and test on your browser.

var days= document.getElementById('days');
var table=document.createElement("table");
var rows=5;
var cols=7;
var counter=1;
var todaysDate = new Date().getDate();
for(var i=1;i<=rows;i++){
   var tr=document.createElement("tr");
for(var j=1;j<=cols;j++)
var td=document.createElement("td");
var cellText =document.createTextNode(counter);

Output Result :

calendar in html

I hope you will learn how to use the nested loop in HTML and javascript to create a beautiful calendar and loop block of statements. Keep support us and copy code and tested on your browser and download the code link below.
Previous Post Next Post