> ## Documentation Index
> Fetch the complete documentation index at: https://blog.sumathi.dev/llms.txt
> Use this file to discover all available pages before exploring further.

#  For Loops

* To perform repeated actions , to automate tasks

## Types of Loops

* The for loop
  * ```js theme={null}
      for (statement 1 ; statement 2 ; statement 3) {
              // code to be executed
          }
    ```
  * statement 1 is executed one time
  * statement 2 is condition based on which loop runs
  * statement 3 is executed everytime the loop body gets executed
  * ```js theme={null}
      // Program to add first n natural numbers
      let sum = 0 ;
      let n = 100;

      for (let i = 1 ; i <= n ; i ++) {

          console.log(i);
          sum += i ;
          console.log("sum of first "+ i +" Natural number is", sum);
      }
    ```
* For in Loop
  * works on objects and arrays
  * ```js theme={null}
      // For in loop

      let obj = {
          kalyan : 10,
          kiran : 8,
          suma : 5,
          raj : 9
      }
      for (let a in obj) {
          console.log("Keys of obj are " + a + ", Values are " + obj[a]);
      }
    ```
* For off loop
  * works on strigs and arrays , they should be iterable
  * ```js theme={null}
      // For off loop th obj should be iterarable like string or array
      // Works on arrays and strings
      for (let b of "kalyan") {
          console.log(b);
      }
    ```
