In javascript a for loop is used for executing a piece of code repeatedly.
In the following sample we are writing almost same code repeatedly in alert box( only the index number in square brackets is changed ).
var languages= ['c#','java','javascript','c'];
alert(languages[0]);
alert(languages[1]);
alert(languages[2]);
alert(languages[3]);

for loop Syntax:

for(variablename=intialvalue;booleanexpression;increment/decrement){
  //some repeating code goes here.
}
Note:loops are used for eliminating repeating code. The following sample eliminates duplicate or repeating code.
var languages= ['c#','java','javascript','c'];
for (i=0; i < languages.length; i++) {
alert(languages[i]);
}