For Loops in Javascript

Updated on 01 Mar 2012,
Published on 10 Mar 2008

For loop in javascript is most often used to execute a particular block of code with different value each time. So, to reduce the code length instead of adding number of code lines using different value each time for loop is used to execute the single line multiple times.

JavaScript Basics Examples:

You can see the live samples and examples of JavaScript Basics from the following links:

Syntax of for loop in javascript

for(var varname=startvalue; varname<=endvalue; varname++)
{
    // Code block to be executed here each time;
}

Example of For Loop in JavaScript

for(var i=1;i<=7;i++)
{
    document.write('<font size=\"' + i + '\">Hello World</font><br />');
}

Above example shows the use of for loop in JavaScript by executing a single line of code how you can increase the size of font in each loop by incrementing the value of variable i.

Output:

You can see the output of above discussed codes from the following link:

JavaScript For Loop

Continue to next tutorial: Javascript While Loops to learn the other way of Javascript iterations using while loop.

0 Responses to "For Loops in Javascript"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers