for loopThe for loop loops through the elements of an array. grammar:
For loop execution order:
Example: Find the sum of even numbers from 1 to 100 var num=0 for(var i=0;i<=100;i+=2){ //i+=2 means i=i+2 num +=i } console.log("Sum of even numbers: "+num) Double for loopNested loops refer to the grammatical structure of defining another loop statement within a loop statement. For example, in a for loop statement, you can nest another for loop. We call such a for loop statement a double for loop. grammar:
The essence of the double for loop is:
Example: Output the multiplication table for(var i= 0 ; i <= 9 ; i++){ for(var aa = 1 ; aa <i+1 ; aa++){ document.write(aa+"*"+i+"="+i*aa); } document.write("<br />"); } You can add some styles to make it more beautiful (add a span element to define the width of the body, change the span element to an inline-block element, and set its fixed width) <head> <style> body{ width:2000px; } span{ display:inline-block; width:80px; } </style> </head> <body> <script> for(var i= 0 ; i <= 9 ; i++){ for(var aa = 1 ; aa <i+1 ; aa++){ document.write("<span>"+aa+"*"+i+"="+i*aa+"</span>"); } document.write("<br />"); } </script> </body> SummarizeThis concludes this article about for loops and double for loops in JavaScript. For more information about JavaScript double for loops, please search previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to import/save/load/delete images locally in Docker
>>: mysql solves the problem of finding records where two or more fields are NULL
Today I will share with you a breathing carousel ...
Table of contents introduce 1. Pica 2. Lena.js 3....
The steps for configuring Tomcat in IDEA 2020 are...
When a request is sent to your server to display ...
What products do you want to mention? Recently, t...
1. Wireless Run PowerShell and enter the command:...
1. A static page means that there are only HTML ta...
This article example shares the specific code of ...
This article describes how to install mysql5.7.16...
<div class="box"> <img /> &...
Introduction yum (Yellow dog Updater, Modified) i...
Table of contents 1. Analysis of key source code ...
When the same function and HTML code are used mul...
Today I want to summarize several very useful HTML...
Table of contents 1. Short circuit judgment 2. Op...