Loops in Javascripts

  1. While loop
  2. For loop
  3. do while loop
  4. Loops for Arrays and Objects

  5. for in loop
  6. for of loop

Difference Between Loops, Workflow

  1. For loop is used , when number of iteration is fixed
  2. while, when we dont know number of iterations
  3. Do while, run atleast one time , even if condition is falsed !
  4. Map method , Transform data & return new array.
  5. For In , return Indexs
  6. For Of , Return Elements
  7. For Each , Returns Index, elemnts

JavaScript File Code:

        
// Loops in Javascripts !

// while loop 

// Print number 1 to 100
let a = 1;
while (a<=100) {
    document.writeln(a);
        a++;
}

document.writeln("

"); // Print number 1 to 100 in Reverse let b = 100; while (b>=1) { document.writeln(b); b--; } document.writeln("

"); // program to reduce one number let n = 563; while (n>0) { n = Math.floor(n/10); document.writeln(n); } document.writeln("

"); // Write a program to reverse a number let c = 123; // storing final value in rev variable let rev = 0; while (c>0) { // rem = storing reminder value ! let rem = c % 10; // creating formula , rev = rev * 10 + rem; c = Math.floor(c / 10); } document.writeln(rev); document.writeln("

"); // Create To find Factorial of a Number ! home work // For Loop // to print number 1 to 20 for (let g = 1; g <= 20; g++) { document.writeln(g); } document.writeln("

"); // to print hello-text 10 times for (let h = 1; h <= 20; h++) { document.writeln("Hello"); } // For loop is used , when number of iteration is fixed // while, when we dont know number of iterations // Do while, run atleast one time , even if condition is falsed ! // Map method , Transform data & return new array. // For In , return Indexs // For Of , Return Elements // For Each , Returns Index, elemnts // All those Solution to find is to check your problem solving in math and coding / LANGUAGE

Javascript Output !