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 

Comments

Anonymous at 06 Feb, 2008 02:24
Im building a form, and all the information in the inputs, i want in a text area like a log. if anyone can help thanks
Reply to this.
Comment


Comment




Comment Formating : HTML tags a, strong, em, b, i, code, pre, p and br allowed. Other tags will be shown as code(< will become &lt;). Urls, Line breaks will be auto-formated.