Previous
Switch Case 
Next
While Loop 
ABC of JavaScript : An Interactive JavaScript Tutorial
For Loop

For Loop

Syntax :
for(INITIALIZATION ; CONDITION ; NEXT) {
BODY
}

The for loop is almost universally held to be the most commonly used loop. This is extremely useful when you have to execute a given set of instruction a limited number of times with little or no changes.

This loop will start with giving a varable a predefined value and then keep on executing the body part of the loop as long as the given condition is true. Every time the loop is executed, the variable gets a new value. Lets see an example to get the concept.

In this example, the for loop starts by giving the variable 'i' the value of 0. Then it will print out the i'th element of the array - one item at a time - till the i variable gets the value 10. Then the loop will be over.

Previous
Switch Case 
Next
While Loop 
blog comments powered by Disqus