Another useful programming structure is the loop. JavaScript provides several ways to repeat commands easily. Let's start with the for loop. The following html was written with JavaScript:
<script language="Javascript" type="text/javascript">
for (var i=1; i<=10; i=i+1)
{
document.write("<strong>This is loop item " + i + "</strong><br />");
}
</script>
A shortcut method of writing the above is as follows:
<script language="javascript" type="text/javascript">
for (i=1; i<=10; i++)
{
document.write("<strong>This is loop item " + i + "</strong><br />");
}
</script>
The same three parameters are used, but with abbreviated coding. i=1 initializes the starting variable, and i++ adds 1 to the variable each time the loop runs (iteration).