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.

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.

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

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.