for
statementS2C Home « Statements « for
Creates a loop structure with three optional expressions.
Description
Creates a loop through a section of code which will be executed n number of times.
Syntax
Signature | Description |
---|---|
for ([initialization]; [condition]; [expression]) | Creates a loop structure with three optional expressions. |
Parameters
Parameter | Description |
---|---|
initialization | An optional (assignment) expression or variable declaration.
|
condition | An optional expression evaluated before each pass through the loop. |
expression | An optional expression evaluated at the end of each pass through the loop. |
statement | Executed when expression evaluates to true . |
Examples
The code below shows some for
loops.
// execute the loop until loop condition is false.
for (var i=0; i<3; i++) {
alert('The i variable is = ' + i);
}
alert('left first for loop');
// execute the loop until loop condition is false.
for (var i=10; i>9; i--) {
alert('The i variable is = ' + i);
}
alert('left second for loop');
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 5 - For Loops