For Loop in Js
For Loop in Js
```javascript
// code to be executed
```
- **Initialization**: It is used to initialize a counter variable before the loop starts. It typically sets the
initial value of the counter variable.
- **Condition**: It specifies the condition that is checked before each iteration of the loop. If the
condition evaluates to `true`, the loop continues executing. If it evaluates to `false`, the loop terminates.
- **Increment/Decrement**: It is used to update the counter variable after each iteration of the loop. It
can be used to increment or decrement the counter.
```javascript
console.log(i);
```
In this example, the `for` loop is initialized with `var i = 1`, which sets the initial value of the counter
variable `i` to 1. The condition `i <= 5` is checked before each iteration. If it evaluates to `true`, the loop
continues executing. After each iteration, the counter `i` is incremented by `i++`. The loop prints the
value of `i` to the console in each iteration, resulting in the output:
```
```
You can also use the `for` loop to iterate over elements in an array or perform other operations.