|
|
|
Quality business correspondence.
|
|
|
|
|
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.
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:
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 conation. The execution
of this example will be same as the previous example.
|
Case Statement
Operators
|
|
|