JavaScript for Loop

Source: Internet
Author: User

Looping JavaScript for loop in JavaScript uses the number of times specified to execute the same code block or the specified condition is true.


Example
For loop
How to write a loop. The number of times that the same code block is run by the closed loop used.

<body>

<script type= "Text/javascript" >
for (i = 0; I <= 5; i++)
{
document.write (http://www.111cn.net + i);
document.write ("<br/>");
}
</script>

</body>

HTML title by looping
How to use the loop loop through different HTML headings.


<script type= "Text/javascript" >
for (i = 1; I <= 6; i++)
{
document.write ("document.write ("}
</script>

The looping of JavaScript
Often when you write code, you want the same piece of code to run over and over again in a row. Instead of adding almost equal line scripts, we can use loops to perform such tasks.

There are two different types of loops in javascript:

is the number of times specified by the loop through the code block.
And-Loop through the code block, while the specified condition is real



For loop
The For loop is used when you know in advance how many times the script should run.

Grammar

for (var=startvalue;var<=endvalue;var=var+increment) 
{
    www.111cn.net/wy/yw.html
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.