ASP Net Center.com
JavaScript
Introduction
Variables & Arrays
Functions
If Statements
Case Statements
Loop Statements
Alert
Form Processing
Date Objects
Window Objects

JavaScript Loops

Loops are set of instructions that repeat elements in specific number of times.  Counter variable is used to increment or decrement with each repetition of the loop.  The two major groups of loops are, For..Next and Do..Loop.  While..Wend is another type of Do..Loop.  The For statements are best used when you want to perform a loop in specific number of times. The Do and While statements are best used to perform a loop an undetermined number of times.
For..Loop syntax example.
for(i=0;i<value; i++)
{
   javascript statement
}

This example increments a variable i from 0 to value and continues performing java script statements while i is less then value.
Here is For..loop example.
<html>
<body>
<script type="text/javascript">
for (i = 0; i <= 4; i++)
{
alert("Current value of i is " + i)
}
</script>
</body>
</html>

This display the value like this on alert boxes: 0,1,2,3,4. The for loop sets i equal to 0 and continues displaying values on an alert boxes as long as i is less than , or equal to, 4. The value of i will increase by 1 each time the loop runs.
To view how the result would execute, click the button:
While..Loop
The While..Loop structure repeats a block of statements until a specified condition is met. 
Bellow is syntax for While..loop:
while(variable=value)
{
   javascript statement
}
The above syntax simply repeats some javascript statements while condition tested false.
Bellow is simple example of while loop:
<html>
<body>
<script type="text/javascript">
var x=5*5;
x=prompt("What is 5 x 5?");
while (x != 25)
{
alert("Wrong answer");
x=prompt("What is 5 x 5?",0);
}
document.write("Right, the answer is " + x)
</script>
</body>
</html>
For this example, we declared variable x and initialized 25. We set it equal to prompt box. The prompt box asks the product of 5x5 and continues asking until true answer is provided. It also informs each wrong attempts or each loop.
To view how this code will execute, click the button:
Bellow is the same example but performs the test at the end of the loop. This time, Do..Loop is used. Using this loop, true value is tested.
<html>
<body>
<script type="text/javascript">
var x = 5*5;
do
{
x=prompt("What is 5 x 5?",0);
}
while (x != 25)
document.write("Right, the answer is " + x)
</script>
</body>
</html>

The syntax are same for Do..While and While but keep in mind one tests false condition and the other tests true condtion. The execution of this example will be same as the previous example.
Case Statement Operators