Archive for April 23, 2007

JavaScript FOR Loop Example

Posted in JavaScript, Software, Web, internet, programming on April 23, 2007 by Joey

var LoopNumber = 5;
for (i=1;i<=LoopNumber;i++)
{
alert(i);
}

The preceding codes works as follows:

The loop variable (i) is initiated at a certain number – in this case 1.

A condition is set for when the loop should end – in this case it is when the loop variable has been incremented to a number greater than 5.

The loop variable is incremented. The loop variable could alternatively be decremented here by using two minus signs (–).