JavaScript for Loop
JavaScript for Loop
The for statement is used to define a block of code that is executed as long as a condition is true.
Syntax:-
Its syntax is:-
for (statement 1; statement 2; statement 3) {
// code block to be executed
}
Further Explanation:-
Parameter | Description |
statement 1 | Optional. Normally it is used to initialize a counter variable. Executed before the code block starts. |
statement 2 | Optional. The condition for running the code block. Loop will continue to execute as long this condition remains true. |
statement 3 | Optional. Normally used to increment or decrement. Executed after the code block. |